PR c++/3478
[official-gcc.git] / gcc / toplev.c
blob478193951e3cc7484f1c0a294504a218c50ef304
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
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. */
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "input.h"
44 #include "tree.h"
45 #include "rtl.h"
46 #include "tm_p.h"
47 #include "flags.h"
48 #include "insn-attr.h"
49 #include "insn-config.h"
50 #include "insn-flags.h"
51 #include "hard-reg-set.h"
52 #include "recog.h"
53 #include "output.h"
54 #include "except.h"
55 #include "function.h"
56 #include "toplev.h"
57 #include "expr.h"
58 #include "basic-block.h"
59 #include "intl.h"
60 #include "ggc.h"
61 #include "graph.h"
62 #include "loop.h"
63 #include "regs.h"
64 #include "timevar.h"
65 #include "diagnostic.h"
66 #include "params.h"
67 #include "reload.h"
68 #include "dwarf2asm.h"
69 #include "integrate.h"
70 #include "real.h"
71 #include "debug.h"
72 #include "target.h"
73 #include "langhooks.h"
74 #include "cfglayout.h"
75 #include "cfgloop.h"
76 #include "hosthooks.h"
77 #include "cgraph.h"
78 #include "opts.h"
79 #include "coverage.h"
80 #include "value-prof.h"
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
84 #endif
86 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
87 #include "dbxout.h"
88 #endif
90 #ifdef SDB_DEBUGGING_INFO
91 #include "sdbout.h"
92 #endif
94 #ifdef XCOFF_DEBUGGING_INFO
95 #include "xcoffout.h" /* Needed for external data
96 declarations for e.g. AIX 4.x. */
97 #endif
99 /* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
102 extern int size_directive_output;
103 extern tree last_assemble_variable_decl;
105 extern void reg_alloc (void);
107 static void general_init (const char *);
108 static void do_compile (void);
109 static void process_options (void);
110 static void backend_init (void);
111 static int lang_dependent_init (const char *);
112 static void init_asm_output (const char *);
113 static void finalize (void);
115 static void crash_signal (int) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
119 static int print_single_switch (FILE *, int, int, const char *,
120 const char *, const char *,
121 const char *, const char *);
122 static void print_switch_values (FILE *, int, int, const char *,
123 const char *, const char *);
125 /* Rest of compilation helper functions. */
126 static bool rest_of_handle_inlining (tree);
127 static void rest_of_handle_cse (tree, rtx);
128 static void rest_of_handle_cse2 (tree, rtx);
129 static void rest_of_handle_gcse (tree, rtx);
130 static void rest_of_handle_life (tree, rtx);
131 static void rest_of_handle_loop_optimize (tree, rtx);
132 static void rest_of_handle_loop2 (tree, rtx);
133 static void rest_of_handle_jump_bypass (tree, rtx);
134 static void rest_of_handle_sibling_calls (rtx);
135 static void rest_of_handle_null_pointer (tree, rtx);
136 static void rest_of_handle_addressof (tree, rtx);
137 static void rest_of_handle_cfg (tree, rtx);
138 static void rest_of_handle_branch_prob (tree, rtx);
139 static void rest_of_handle_value_profile_transformations (tree, rtx);
140 static void rest_of_handle_if_conversion (tree, rtx);
141 static void rest_of_handle_if_after_combine (tree, rtx);
142 static void rest_of_handle_tracer (tree, rtx);
143 static void rest_of_handle_combine (tree, rtx);
144 static void rest_of_handle_regmove (tree, rtx);
145 #ifdef INSN_SCHEDULING
146 static void rest_of_handle_sched (tree, rtx);
147 static void rest_of_handle_sched2 (tree, rtx);
148 #endif
149 static bool rest_of_handle_new_regalloc (tree, rtx);
150 static bool rest_of_handle_old_regalloc (tree, rtx);
151 static void rest_of_handle_regrename (tree, rtx);
152 static void rest_of_handle_reorder_blocks (tree, rtx);
153 #ifdef STACK_REGS
154 static void rest_of_handle_stack_regs (tree, rtx);
155 #endif
156 static void rest_of_handle_machine_reorg (tree, rtx);
157 #ifdef DELAY_SLOTS
158 static void rest_of_handle_delay_slots (tree, rtx);
159 #endif
160 static void rest_of_handle_final (tree, rtx);
162 /* Nonzero to dump debug info whilst parsing (-dy option). */
163 static int set_yydebug;
165 /* True if we don't need a backend (e.g. preprocessing only). */
166 static bool no_backend;
168 /* Length of line when printing switch values. */
169 #define MAX_LINE 75
171 /* Name of program invoked, sans directories. */
173 const char *progname;
175 /* Copy of argument vector to toplev_main. */
176 static const char **save_argv;
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. */
182 const char *main_input_filename;
184 /* Current position in real source file. */
186 location_t input_location;
188 /* Nonzero if it is unsafe to create any new pseudo registers. */
189 int no_new_pseudos;
191 /* Stack of currently pending input files. */
193 struct file_stack *input_file_stack;
195 /* Incremented on each change to input_file_stack. */
196 int input_file_stack_tick;
198 /* Name to use as base of names for dump output files. */
200 const char *dump_base_name;
202 /* Name to use as a base for auxiliary output files. */
204 const char *aux_base_name;
206 /* Format to use to print dumpfile index value */
207 #ifndef DUMPFILE_FORMAT
208 #define DUMPFILE_FORMAT ".%02d."
209 #endif
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. */
215 extern int target_flags;
217 /* A mask of target_flags that includes bit X if X was set or cleared
218 on the command line. */
220 int target_flags_explicit;
222 /* Debug hooks - dependent upon command line options. */
224 const struct gcc_debug_hooks *debug_hooks;
226 /* Describes a dump file. */
228 struct dump_file_info
230 /* The unique extension to apply, e.g. ".jump". */
231 const char *const extension;
233 /* The -d<c> character that enables this dump file. */
234 char const debug_switch;
236 /* True if there is a corresponding graph dump file. */
237 char const graph_dump_p;
239 /* True if the user selected this dump. */
240 char enabled;
242 /* True if the files have been initialized (ie truncated). */
243 char initialized;
246 /* Enumerate the extant dump files. */
248 enum dump_file_index
250 DFI_cgraph,
251 DFI_rtl,
252 DFI_sibling,
253 DFI_eh,
254 DFI_jump,
255 DFI_null,
256 DFI_cse,
257 DFI_addressof,
258 DFI_gcse,
259 DFI_loop,
260 DFI_bypass,
261 DFI_cfg,
262 DFI_bp,
263 DFI_vpt,
264 DFI_ce1,
265 DFI_tracer,
266 DFI_loop2,
267 DFI_web,
268 DFI_cse2,
269 DFI_life,
270 DFI_combine,
271 DFI_ce2,
272 DFI_regmove,
273 DFI_sched,
274 DFI_lreg,
275 DFI_greg,
276 DFI_postreload,
277 DFI_flow2,
278 DFI_peephole2,
279 DFI_rnreg,
280 DFI_ce3,
281 DFI_bbro,
282 DFI_branch_target_load,
283 DFI_sched2,
284 DFI_stack,
285 DFI_mach,
286 DFI_dbr,
287 DFI_MAX
290 /* Describes all the dump files. Should be kept in order of the
291 pass and in sync with dump_file_index above.
293 Remaining -d letters:
295 " e m q "
296 " JK O Q WXY "
299 static struct dump_file_info dump_file[DFI_MAX] =
301 { "cgraph", 'U', 0, 0, 0 },
302 { "rtl", 'r', 0, 0, 0 },
303 { "sibling", 'i', 0, 0, 0 },
304 { "eh", 'h', 0, 0, 0 },
305 { "jump", 'j', 0, 0, 0 },
306 { "null", 'u', 0, 0, 0 },
307 { "cse", 's', 0, 0, 0 },
308 { "addressof", 'F', 0, 0, 0 },
309 { "gcse", 'G', 1, 0, 0 },
310 { "loop", 'L', 1, 0, 0 },
311 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
312 { "cfg", 'f', 1, 0, 0 },
313 { "bp", 'b', 1, 0, 0 },
314 { "vpt", 'V', 1, 0, 0 },
315 { "ce1", 'C', 1, 0, 0 },
316 { "tracer", 'T', 1, 0, 0 },
317 { "loop2", 'L', 1, 0, 0 },
318 { "web", 'Z', 0, 0, 0 },
319 { "cse2", 't', 1, 0, 0 },
320 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
321 { "combine", 'c', 1, 0, 0 },
322 { "ce2", 'C', 1, 0, 0 },
323 { "regmove", 'N', 1, 0, 0 },
324 { "sched", 'S', 1, 0, 0 },
325 { "lreg", 'l', 1, 0, 0 },
326 { "greg", 'g', 1, 0, 0 },
327 { "postreload", 'o', 1, 0, 0 },
328 { "flow2", 'w', 1, 0, 0 },
329 { "peephole2", 'z', 1, 0, 0 },
330 { "rnreg", 'n', 1, 0, 0 },
331 { "ce3", 'E', 1, 0, 0 },
332 { "bbro", 'B', 1, 0, 0 },
333 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
334 { "sched2", 'R', 1, 0, 0 },
335 { "stack", 'k', 1, 0, 0 },
336 { "mach", 'M', 1, 0, 0 },
337 { "dbr", 'd', 0, 0, 0 },
340 static int open_dump_file (enum dump_file_index, tree);
341 static void close_dump_file (enum dump_file_index,
342 void (*) (FILE *, rtx), rtx);
344 /* Other flags saying which kinds of debugging dump have been requested. */
346 int rtl_dump_and_exit;
347 int flag_print_asm_name;
348 enum graph_dump_types graph_dump_format;
350 /* Name for output file of assembly code, specified with -o. */
352 const char *asm_file_name;
354 /* Nonzero means do optimizations. -O.
355 Particular numeric values stand for particular amounts of optimization;
356 thus, -O2 stores 2 here. However, the optimizations beyond the basic
357 ones are not controlled directly by this variable. Instead, they are
358 controlled by individual `flag_...' variables that are defaulted
359 based on this variable. */
361 int optimize = 0;
363 /* Nonzero means optimize for size. -Os.
364 The only valid values are zero and nonzero. When optimize_size is
365 nonzero, optimize defaults to 2, but certain individual code
366 bloating optimizations are disabled. */
368 int optimize_size = 0;
370 /* The FUNCTION_DECL for the function currently being compiled,
371 or 0 if between functions. */
372 tree current_function_decl;
374 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
375 if none. */
376 tree current_function_func_begin_label;
378 /* Nonzero if doing dwarf2 duplicate elimination. */
380 int flag_eliminate_dwarf2_dups = 0;
382 /* Nonzero if doing unused type elimination. */
384 int flag_eliminate_unused_debug_types = 1;
386 /* Nonzero means emit debugging information only for symbols which are used. */
387 int flag_debug_only_used_symbols = 0;
389 /* Nonzero if generating code to do profiling. */
391 int profile_flag = 0;
393 /* Nonzero if generating code to profile program flow graph arcs. */
395 int profile_arc_flag = 0;
397 /* Nonzero if value histograms should be measured. */
399 int flag_profile_values = 0;
401 /* Nonzero if value histograms should be used to optimize code. */
402 int flag_value_profile_transformations = 0;
404 /* Nonzero if generating info for gcov to calculate line test coverage. */
406 int flag_test_coverage = 0;
408 /* Nonzero indicates that branch taken probabilities should be calculated. */
410 int flag_branch_probabilities = 0;
412 /* Nonzero if basic blocks should be reordered. */
414 int flag_reorder_blocks = 0;
416 /* Nonzero if functions should be reordered. */
418 int flag_reorder_functions = 0;
420 /* Nonzero if registers should be renamed. */
422 int flag_rename_registers = 0;
423 int flag_cprop_registers = 0;
425 /* Nonzero for -pedantic switch: warn about anything
426 that standard spec forbids. */
428 int pedantic = 0;
430 /* Temporarily suppress certain warnings.
431 This is set while reading code from a system header file. */
433 int in_system_header = 0;
435 /* Don't print functions as they are compiled. -quiet. */
437 int quiet_flag = 0;
439 /* Print times taken by the various passes. -ftime-report. */
441 int time_report = 0;
443 /* Print memory still in use at end of compilation (which may have little
444 to do with peak memory consumption). -fmem-report. */
446 int mem_report = 0;
448 /* Nonzero means to collect statistics which might be expensive
449 and to print them when we are done. */
450 int flag_detailed_statistics = 0;
452 /* A random sequence of characters, unless overridden by user. */
453 const char *flag_random_seed;
455 /* A local time stamp derived from the time of compilation. It will be
456 zero if the system cannot provide a time. It will be -1u, if the
457 user has specified a particular random seed. */
458 unsigned local_tick;
460 /* -f flags. */
462 /* Nonzero means `char' should be signed. */
464 int flag_signed_char;
466 /* Nonzero means give an enum type only as many bytes as it needs. */
468 int flag_short_enums;
470 /* Nonzero for -fcaller-saves: allocate values in regs that need to
471 be saved across function calls, if that produces overall better code.
472 Optional now, so people can test it. */
474 int flag_caller_saves = 0;
476 /* Nonzero if structures and unions should be returned in memory.
478 This should only be defined if compatibility with another compiler or
479 with an ABI is needed, because it results in slower code. */
481 #ifndef DEFAULT_PCC_STRUCT_RETURN
482 #define DEFAULT_PCC_STRUCT_RETURN 1
483 #endif
485 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
487 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
489 /* Nonzero for -fforce-mem: load memory value into a register
490 before arithmetic on it. This makes better cse but slower compilation. */
492 int flag_force_mem = 0;
494 /* Nonzero for -fforce-addr: load memory address into a register before
495 reference to memory. This makes better cse but slower compilation. */
497 int flag_force_addr = 0;
499 /* Nonzero for -fdefer-pop: don't pop args after each function call;
500 instead save them up to pop many calls' args with one insns. */
502 int flag_defer_pop = 0;
504 /* Nonzero for -ffloat-store: don't allocate floats and doubles
505 in extended-precision registers. */
507 int flag_float_store = 0;
509 /* Nonzero for -fcse-follow-jumps:
510 have cse follow jumps to do a more extensive job. */
512 int flag_cse_follow_jumps;
514 /* Nonzero for -fcse-skip-blocks:
515 have cse follow a branch around a block. */
516 int flag_cse_skip_blocks;
518 /* Nonzero for -fexpensive-optimizations:
519 perform miscellaneous relatively-expensive optimizations. */
520 int flag_expensive_optimizations;
522 /* Nonzero for -fthread-jumps:
523 have jump optimize output of loop. */
525 int flag_thread_jumps;
527 /* Nonzero enables strength-reduction in loop.c. */
529 int flag_strength_reduce = 0;
531 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
532 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
533 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
534 unrolled. */
536 int flag_old_unroll_loops;
538 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
539 This is generally not a win. */
541 int flag_old_unroll_all_loops;
543 /* Enables unrolling of simple loops in loop-unroll.c. */
544 int flag_unroll_loops;
546 /* Enables unrolling of all loops in loop-unroll.c. */
547 int flag_unroll_all_loops;
549 /* Nonzero enables loop peeling. */
550 int flag_peel_loops;
552 /* Nonzero enables loop unswitching. */
553 int flag_unswitch_loops;
555 /* Nonzero enables prefetch optimizations for arrays in loops. */
557 int flag_prefetch_loop_arrays;
559 /* Nonzero forces all invariant computations in loops to be moved
560 outside the loop. */
562 int flag_move_all_movables = 0;
564 /* Nonzero forces all general induction variables in loops to be
565 strength reduced. */
567 int flag_reduce_all_givs = 0;
569 /* Nonzero to perform full register move optimization passes. This is the
570 default for -O2. */
572 int flag_regmove = 0;
574 /* Nonzero for -fwritable-strings:
575 store string constants in data segment and don't uniquize them. */
577 int flag_writable_strings = 0;
579 /* Nonzero means don't put addresses of constant functions in registers.
580 Used for compiling the Unix kernel, where strange substitutions are
581 done on the assembly output. */
583 int flag_no_function_cse = 0;
585 /* Nonzero for -fomit-frame-pointer:
586 don't make a frame pointer in simple functions that don't require one. */
588 int flag_omit_frame_pointer = 0;
590 /* Nonzero means place each function into its own section on those platforms
591 which support arbitrary section names and unlimited numbers of sections. */
593 int flag_function_sections = 0;
595 /* ... and similar for data. */
597 int flag_data_sections = 0;
599 /* Nonzero to inhibit use of define_optimization peephole opts. */
601 int flag_no_peephole = 0;
603 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
605 int flag_optimize_sibling_calls = 0;
607 /* Nonzero means the front end generally wants `errno' maintained by math
608 operations, like built-in SQRT. */
610 int flag_errno_math = 1;
612 /* Nonzero means that unsafe floating-point math optimizations are allowed
613 for the sake of speed. IEEE compliance is not guaranteed, and operations
614 are allowed to assume that their arguments and results are "normal"
615 (e.g., nonnegative for SQRT). */
617 int flag_unsafe_math_optimizations = 0;
619 /* Nonzero means that no NaNs or +-Infs are expected. */
621 int flag_finite_math_only = 0;
623 /* Zero means that floating-point math operations cannot generate a
624 (user-visible) trap. This is the case, for example, in nonstop
625 IEEE 754 arithmetic. Trapping conditions include division by zero,
626 overflow, underflow, invalid and inexact, but does not include
627 operations on signaling NaNs (see below). */
629 int flag_trapping_math = 1;
631 /* Nonzero means disable transformations that assume default floating
632 point rounding behavior. */
634 int flag_rounding_math = 0;
636 /* Nonzero means disable transformations observable by signaling NaNs.
637 This option implies that any operation on an IEEE signaling NaN can
638 generate a (user-visible) trap. */
640 int flag_signaling_nans = 0;
642 /* 0 means straightforward implementation of complex divide acceptable.
643 1 means wide ranges of inputs must work for complex divide.
644 2 means C99-like requirements for complex divide (not yet implemented). */
646 int flag_complex_divide_method = 0;
648 /* Nonzero means just do syntax checking; don't output anything. */
650 int flag_syntax_only = 0;
652 /* Nonzero means performs web construction pass. */
654 int flag_web;
656 /* Nonzero means perform loop optimizer. */
658 int flag_loop_optimize;
660 /* Nonzero means perform crossjumping. */
662 int flag_crossjumping;
664 /* Nonzero means perform if conversion. */
666 int flag_if_conversion;
668 /* Nonzero means perform if conversion after reload. */
670 int flag_if_conversion2;
672 /* Nonzero means to use global dataflow analysis to eliminate
673 useless null pointer tests. */
675 int flag_delete_null_pointer_checks;
677 /* Nonzero means perform global CSE. */
679 int flag_gcse = 0;
681 /* Nonzero means to do the enhanced load motion during gcse, which trys
682 to hoist loads by not killing them when a store to the same location
683 is seen. */
685 int flag_gcse_lm = 1;
687 /* Nonzero means to perform store motion after gcse, which will try to
688 move stores closer to the exit block. Its not very effective without
689 flag_gcse_lm. */
691 int flag_gcse_sm = 1;
693 /* Nonzero if we want to perfrom redundant load after store elimination
694 in gcse. */
696 int flag_gcse_las = 1;
698 /* Perform target register optimization before prologue / epilogue
699 threading. */
701 int flag_branch_target_load_optimize = 0;
703 /* Perform target register optimization after prologue / epilogue
704 threading and jump2. */
706 int flag_branch_target_load_optimize2 = 0;
708 /* Nonzero means to rerun cse after loop optimization. This increases
709 compilation time about 20% and picks up a few more common expressions. */
711 int flag_rerun_cse_after_loop;
713 /* Nonzero means to run loop optimizations twice. */
715 int flag_rerun_loop_opt;
717 /* Nonzero for -finline-functions: ok to inline functions that look like
718 good inline candidates. */
720 int flag_inline_functions;
722 /* Nonzero for -fkeep-inline-functions: even if we make a function
723 go inline everywhere, keep its definition around for debugging
724 purposes. */
726 int flag_keep_inline_functions;
728 /* Nonzero means that functions will not be inlined. */
730 int flag_no_inline = 2;
732 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
733 not just because the tree inliner turned us off. */
735 int flag_really_no_inline = 2;
737 /* Nonzero means that we should emit static const variables
738 regardless of whether or not optimization is turned on. */
740 int flag_keep_static_consts = 1;
742 /* Nonzero means we should be saving declaration info into a .X file. */
744 int flag_gen_aux_info = 0;
746 /* Specified name of aux-info file. */
748 const char *aux_info_file_name;
750 /* Nonzero means make the text shared if supported. */
752 int flag_shared_data;
754 /* Nonzero means schedule into delayed branch slots if supported. */
756 int flag_delayed_branch;
758 /* Nonzero if we are compiling pure (sharable) code.
759 Value is 1 if we are doing "small" pic; value is 2 if we're doing
760 "large" pic. */
762 int flag_pic;
764 /* Nonzero if we are compiling position independent code for executable.
765 The value is 1 if we are doing "small" pic; value is 2 if we're doing
766 "large" pic. */
768 int flag_pie;
770 /* Nonzero if we are compiling code for a shared library, zero for
771 executable. */
773 int flag_shlib;
775 /* Set to the default thread-local storage (tls) model to use. */
777 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
779 /* Nonzero means generate extra code for exception handling and enable
780 exception handling. */
782 int flag_exceptions;
784 /* Nonzero means generate frame unwind info table when supported. */
786 int flag_unwind_tables = 0;
788 /* Nonzero means generate frame unwind info table exact at each insn
789 boundary. */
791 int flag_asynchronous_unwind_tables = 0;
793 /* Nonzero means don't place uninitialized global data in common storage
794 by default. */
796 int flag_no_common;
798 /* Nonzero means change certain warnings into errors.
799 Usually these are warnings about failure to conform to some standard. */
801 int flag_pedantic_errors = 0;
803 /* flag_schedule_insns means schedule insns within basic blocks (before
804 local_alloc).
805 flag_schedule_insns_after_reload means schedule insns after
806 global_alloc. */
808 int flag_schedule_insns = 0;
809 int flag_schedule_insns_after_reload = 0;
811 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
812 int flag_sched2_use_superblocks = 0;
814 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
815 scheduler. */
816 int flag_sched2_use_traces = 0;
818 /* The following flags have effect only for scheduling before register
819 allocation:
821 flag_schedule_interblock means schedule insns across basic blocks.
822 flag_schedule_speculative means allow speculative motion of non-load insns.
823 flag_schedule_speculative_load means allow speculative motion of some
824 load insns.
825 flag_schedule_speculative_load_dangerous allows speculative motion of more
826 load insns. */
828 int flag_schedule_interblock = 1;
829 int flag_schedule_speculative = 1;
830 int flag_schedule_speculative_load = 0;
831 int flag_schedule_speculative_load_dangerous = 0;
833 /* The following flags have an effect during scheduling after register
834 allocation:
836 flag_sched_stalled_insns means that insns can be moved prematurely from the queue
837 of stalled insns into the ready list.
839 flag_sched_stalled_insns_dep controls how many insn groups will be examined
840 for a dependency on a stalled insn that is candidate for premature removal
841 from the queue of stalled insns into the ready list (has an effect only if
842 the flag 'sched_stalled_insns' is set). */
844 int flag_sched_stalled_insns = 0;
845 int flag_sched_stalled_insns_dep = 1;
847 int flag_single_precision_constant;
849 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
850 by a cheaper branch on a count register. */
851 int flag_branch_on_count_reg = 1;
853 /* -finhibit-size-directive inhibits output of .size for ELF.
854 This is used only for compiling crtstuff.c,
855 and it may be extended to other effects
856 needed for crtstuff.c on other systems. */
857 int flag_inhibit_size_directive = 0;
859 /* -fverbose-asm causes extra commentary information to be produced in
860 the generated assembly code (to make it more readable). This option
861 is generally only of use to those who actually need to read the
862 generated assembly code (perhaps while debugging the compiler itself).
863 -fno-verbose-asm, the default, causes the extra information
864 to be omitted and is useful when comparing two assembler files. */
866 int flag_verbose_asm = 0;
868 /* -dA causes debug commentary information to be produced in
869 the generated assembly code (to make it more readable). This option
870 is generally only of use to those who actually need to read the
871 generated assembly code (perhaps while debugging the compiler itself).
872 Currently, this switch is only used by dwarfout.c; however, it is intended
873 to be a catchall for printing debug information in the assembler file. */
875 int flag_debug_asm = 0;
877 /* -dP causes the rtl to be emitted as a comment in assembly. */
879 int flag_dump_rtl_in_asm = 0;
881 /* Nonzero means put zero initialized data in the bss section. */
882 int flag_zero_initialized_in_bss = 1;
884 /* Tag all structures with __attribute__(packed). */
885 int flag_pack_struct = 0;
887 /* Emit code to check for stack overflow; also may cause large objects
888 to be allocated dynamically. */
889 int flag_stack_check;
891 /* When non-NULL, indicates that whenever space is allocated on the
892 stack, the resulting stack pointer must not pass this
893 address---that is, for stacks that grow downward, the stack pointer
894 must always be greater than or equal to this address; for stacks
895 that grow upward, the stack pointer must be less than this address.
896 At present, the rtx may be either a REG or a SYMBOL_REF, although
897 the support provided depends on the backend. */
898 rtx stack_limit_rtx;
900 /* 0 if pointer arguments may alias each other. True in C.
901 1 if pointer arguments may not alias each other but may alias
902 global variables.
903 2 if pointer arguments may not alias each other and may not
904 alias global variables. True in Fortran.
905 This defaults to 0 for C. */
906 int flag_argument_noalias = 0;
908 /* Nonzero if we should do (language-dependent) alias analysis.
909 Typically, this analysis will assume that expressions of certain
910 types do not alias expressions of certain other types. Only used
911 if alias analysis (in general) is enabled. */
912 int flag_strict_aliasing = 0;
914 /* Instrument functions with calls at entry and exit, for profiling. */
915 int flag_instrument_function_entry_exit = 0;
917 /* Nonzero means ignore `#ident' directives. 0 means handle them.
918 On SVR4 targets, it also controls whether or not to emit a
919 string identifying the compiler. */
921 int flag_no_ident = 0;
923 /* This will perform a peephole pass before sched2. */
924 int flag_peephole2 = 0;
926 /* This will try to guess branch probabilities. */
927 int flag_guess_branch_prob = 0;
929 /* -fcheck-bounds causes gcc to generate array bounds checks.
930 For C, C++, ObjC: defaults to off.
931 For Java: defaults to on.
932 For Fortran: defaults to off. */
933 int flag_bounds_check = 0;
935 /* This will attempt to merge constant section constants, if 1 only
936 string constants and constants from constant pool, if 2 also constant
937 variables. */
938 int flag_merge_constants = 1;
940 /* If one, renumber instruction UIDs to reduce the number of
941 unused UIDs if there are a lot of instructions. If greater than
942 one, unconditionally renumber instruction UIDs. */
943 int flag_renumber_insns = 1;
945 /* If nonzero, use the graph coloring register allocator. */
946 int flag_new_regalloc = 0;
948 /* Nonzero if we perform superblock formation. */
950 int flag_tracer = 0;
952 /* Nonzero if we perform whole unit at a time compilation. */
954 int flag_unit_at_a_time = 0;
956 /* Values of the -falign-* flags: how much to align labels in code.
957 0 means `use default', 1 means `don't align'.
958 For each variable, there is an _log variant which is the power
959 of two not less than the variable, for .align output. */
961 int align_loops;
962 int align_loops_log;
963 int align_loops_max_skip;
964 int align_jumps;
965 int align_jumps_log;
966 int align_jumps_max_skip;
967 int align_labels;
968 int align_labels_log;
969 int align_labels_max_skip;
970 int align_functions;
971 int align_functions_log;
973 /* Like align_functions_log above, but used by front-ends to force the
974 minimum function alignment. Zero means no alignment is forced. */
975 int force_align_functions_log;
977 typedef struct
979 const char *const string;
980 int *const variable;
981 const int on_value;
983 lang_independent_options;
985 /* Nonzero if signed arithmetic overflow should trap. */
986 int flag_trapv = 0;
988 /* Nonzero if signed arithmetic overflow should wrap around. */
989 int flag_wrapv = 0;
991 /* Nonzero if subexpressions must be evaluated from left-to-right. */
992 int flag_evaluation_order = 0;
994 /* Add or remove a leading underscore from user symbols. */
995 int flag_leading_underscore = -1;
997 /* The user symbol prefix after having resolved same. */
998 const char *user_label_prefix;
1000 static const param_info lang_independent_params[] = {
1001 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1002 { OPTION, DEFAULT, HELP },
1003 #include "params.def"
1004 #undef DEFPARAM
1005 { NULL, 0, NULL }
1008 /* Table of language-independent -f options.
1009 STRING is the option name. VARIABLE is the address of the variable.
1010 ON_VALUE is the value to store in VARIABLE
1011 if `-fSTRING' is seen as an option.
1012 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1014 static const lang_independent_options f_options[] =
1016 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1017 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1018 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1019 {"float-store", &flag_float_store, 1 },
1020 {"defer-pop", &flag_defer_pop, 1 },
1021 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1022 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1023 {"tracer", &flag_tracer, 1 },
1024 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1025 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1026 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1027 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1028 {"thread-jumps", &flag_thread_jumps, 1 },
1029 {"strength-reduce", &flag_strength_reduce, 1 },
1030 {"unroll-loops", &flag_unroll_loops, 1 },
1031 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1032 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1033 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1034 {"peel-loops", &flag_peel_loops, 1 },
1035 {"unswitch-loops", &flag_unswitch_loops, 1 },
1036 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1037 {"move-all-movables", &flag_move_all_movables, 1 },
1038 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1039 {"writable-strings", &flag_writable_strings, 1 },
1040 {"peephole", &flag_no_peephole, 0 },
1041 {"force-mem", &flag_force_mem, 1 },
1042 {"force-addr", &flag_force_addr, 1 },
1043 {"function-cse", &flag_no_function_cse, 0 },
1044 {"inline-functions", &flag_inline_functions, 1 },
1045 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1046 {"inline", &flag_no_inline, 0 },
1047 {"keep-static-consts", &flag_keep_static_consts, 1 },
1048 {"syntax-only", &flag_syntax_only, 1 },
1049 {"shared-data", &flag_shared_data, 1 },
1050 {"caller-saves", &flag_caller_saves, 1 },
1051 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1052 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1053 {"delayed-branch", &flag_delayed_branch, 1 },
1054 {"web", &flag_web, 1},
1055 {"gcse", &flag_gcse, 1 },
1056 {"gcse-lm", &flag_gcse_lm, 1 },
1057 {"gcse-sm", &flag_gcse_sm, 1 },
1058 {"gcse-las", &flag_gcse_las, 1 },
1059 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1060 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1061 {"loop-optimize", &flag_loop_optimize, 1 },
1062 {"crossjumping", &flag_crossjumping, 1 },
1063 {"if-conversion", &flag_if_conversion, 1 },
1064 {"if-conversion2", &flag_if_conversion2, 1 },
1065 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1066 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1067 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1068 {"schedule-insns", &flag_schedule_insns, 1 },
1069 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1070 {"sched-interblock",&flag_schedule_interblock, 1 },
1071 {"sched-spec",&flag_schedule_speculative, 1 },
1072 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1073 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1074 {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
1075 {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
1076 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1077 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1078 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1079 {"pic", &flag_pic, 1 },
1080 {"PIC", &flag_pic, 2 },
1081 {"pie", &flag_pie, 1 },
1082 {"PIE", &flag_pie, 2 },
1083 {"exceptions", &flag_exceptions, 1 },
1084 {"unwind-tables", &flag_unwind_tables, 1 },
1085 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1086 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1087 {"profile-arcs", &profile_arc_flag, 1 },
1088 {"profile-values", &flag_profile_values, 1 },
1089 {"vpt", &flag_value_profile_transformations, 1 },
1090 {"test-coverage", &flag_test_coverage, 1 },
1091 {"branch-probabilities", &flag_branch_probabilities, 1 },
1092 {"profile", &profile_flag, 1 },
1093 {"reorder-blocks", &flag_reorder_blocks, 1 },
1094 {"reorder-functions", &flag_reorder_functions, 1 },
1095 {"rename-registers", &flag_rename_registers, 1 },
1096 {"cprop-registers", &flag_cprop_registers, 1 },
1097 {"common", &flag_no_common, 0 },
1098 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1099 {"function-sections", &flag_function_sections, 1 },
1100 {"data-sections", &flag_data_sections, 1 },
1101 {"verbose-asm", &flag_verbose_asm, 1 },
1102 {"regmove", &flag_regmove, 1 },
1103 {"optimize-register-move", &flag_regmove, 1 },
1104 {"pack-struct", &flag_pack_struct, 1 },
1105 {"stack-check", &flag_stack_check, 1 },
1106 {"argument-alias", &flag_argument_noalias, 0 },
1107 {"argument-noalias", &flag_argument_noalias, 1 },
1108 {"argument-noalias-global", &flag_argument_noalias, 2 },
1109 {"strict-aliasing", &flag_strict_aliasing, 1 },
1110 {"align-loops", &align_loops, 0 },
1111 {"align-jumps", &align_jumps, 0 },
1112 {"align-labels", &align_labels, 0 },
1113 {"align-functions", &align_functions, 0 },
1114 {"merge-constants", &flag_merge_constants, 1 },
1115 {"merge-all-constants", &flag_merge_constants, 2 },
1116 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1117 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1118 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1119 {"leading-underscore", &flag_leading_underscore, 1 },
1120 {"ident", &flag_no_ident, 0 },
1121 { "peephole2", &flag_peephole2, 1 },
1122 {"finite-math-only", &flag_finite_math_only, 1 },
1123 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1124 {"math-errno", &flag_errno_math, 1 },
1125 {"trapping-math", &flag_trapping_math, 1 },
1126 {"rounding-math", &flag_rounding_math, 1 },
1127 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1128 {"signaling-nans", &flag_signaling_nans, 1 },
1129 {"bounds-check", &flag_bounds_check, 1 },
1130 {"single-precision-constant", &flag_single_precision_constant, 1 },
1131 {"time-report", &time_report, 1 },
1132 {"mem-report", &mem_report, 1 },
1133 { "trapv", &flag_trapv, 1 },
1134 { "wrapv", &flag_wrapv, 1 },
1135 { "new-ra", &flag_new_regalloc, 1 }
1138 /* Here is a table, controlled by the tm.h file, listing each -m switch
1139 and which bits in `target_switches' it should set or clear.
1140 If VALUE is positive, it is bits to set.
1141 If VALUE is negative, -VALUE is bits to clear.
1142 (The sign bit is not used so there is no confusion.) */
1144 static const struct
1146 const char *const name;
1147 const int value;
1148 const char *const description;
1150 target_switches[] = TARGET_SWITCHES;
1152 /* This table is similar, but allows the switch to have a value. */
1154 #ifdef TARGET_OPTIONS
1155 static const struct
1157 const char *const prefix;
1158 const char **const variable;
1159 const char *const description;
1160 const char *const value;
1162 target_options[] = TARGET_OPTIONS;
1163 #endif
1165 /* Nonzero means warn about function definitions that default the return type
1166 or that use a null return and have a return-type other than void. */
1168 int warn_return_type;
1170 /* Output files for assembler code (real compiler output)
1171 and debugging dumps. */
1173 FILE *asm_out_file;
1174 FILE *aux_info_file;
1175 FILE *rtl_dump_file = NULL;
1176 FILE *cgraph_dump_file = NULL;
1178 /* The current working directory of a translation. It's generally the
1179 directory from which compilation was initiated, but a preprocessed
1180 file may specify the original directory in which it was
1181 created. */
1183 static const char *src_pwd;
1185 /* Initialize src_pwd with the given string, and return true. If it
1186 was already initialized, return false. As a special case, it may
1187 be called with a NULL argument to test whether src_pwd has NOT been
1188 initialized yet. */
1190 bool
1191 set_src_pwd (const char *pwd)
1193 if (src_pwd)
1194 return false;
1196 src_pwd = xstrdup (pwd);
1197 return true;
1200 /* Return the directory from which the translation unit was initiated,
1201 in case set_src_pwd() was not called before to assign it a
1202 different value. */
1204 const char *
1205 get_src_pwd (void)
1207 if (! src_pwd)
1208 src_pwd = getpwd ();
1210 return src_pwd;
1213 /* Called when the start of a function definition is parsed,
1214 this function prints on stderr the name of the function. */
1215 void
1216 announce_function (tree decl)
1218 if (!quiet_flag)
1220 if (rtl_dump_and_exit)
1221 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1222 else
1223 verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
1224 fflush (stderr);
1225 pp_needs_newline (global_dc->printer) = true;
1226 diagnostic_set_last_function (global_dc);
1230 /* Set up a default flag_random_seed and local_tick, unless the user
1231 already specified one. */
1233 static void
1234 randomize (void)
1236 if (!flag_random_seed)
1238 unsigned HOST_WIDE_INT value;
1239 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1241 /* Get some more or less random data. */
1242 #ifdef HAVE_GETTIMEOFDAY
1244 struct timeval tv;
1246 gettimeofday (&tv, NULL);
1247 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1249 #else
1251 time_t now = time (NULL);
1253 if (now != (time_t)-1)
1254 local_tick = (unsigned) now;
1256 #endif
1257 value = local_tick ^ getpid ();
1259 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1260 flag_random_seed = random_seed;
1262 else if (!local_tick)
1263 local_tick = -1;
1267 /* Decode the string P as an integral parameter.
1268 If the string is indeed an integer return its numeric value else
1269 issue an Invalid Option error for the option PNAME and return DEFVAL.
1270 If PNAME is zero just return DEFVAL, do not call error. */
1273 read_integral_parameter (const char *p, const char *pname, const int defval)
1275 const char *endp = p;
1277 while (*endp)
1279 if (ISDIGIT (*endp))
1280 endp++;
1281 else
1282 break;
1285 if (*endp != 0)
1287 if (pname != 0)
1288 error ("invalid option argument `%s'", pname);
1289 return defval;
1292 return atoi (p);
1295 /* Return the logarithm of X, base 2, considering X unsigned,
1296 if X is a power of 2. Otherwise, returns -1.
1298 This should be used via the `exact_log2' macro. */
1301 exact_log2_wide (unsigned HOST_WIDE_INT x)
1303 int log = 0;
1304 /* Test for 0 or a power of 2. */
1305 if (x == 0 || x != (x & -x))
1306 return -1;
1307 while ((x >>= 1) != 0)
1308 log++;
1309 return log;
1312 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1313 If X is 0, return -1.
1315 This should be used via the floor_log2 macro. */
1318 floor_log2_wide (unsigned HOST_WIDE_INT x)
1320 int log = -1;
1321 while (x != 0)
1322 log++,
1323 x >>= 1;
1324 return log;
1327 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1328 into ICE messages, which is much more user friendly. In case the
1329 error printer crashes, reset the signal to prevent infinite recursion. */
1331 static void
1332 crash_signal (int signo)
1334 signal (signo, SIG_DFL);
1335 internal_error ("%s", strsignal (signo));
1338 /* Arrange to dump core on error. (The regular error message is still
1339 printed first, except in the case of abort().) */
1341 static void
1342 setup_core_dumping (void)
1344 #ifdef SIGABRT
1345 signal (SIGABRT, SIG_DFL);
1346 #endif
1347 #if defined(HAVE_SETRLIMIT)
1349 struct rlimit rlim;
1350 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1351 fatal_error ("getting core file size maximum limit: %m");
1352 rlim.rlim_cur = rlim.rlim_max;
1353 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1354 fatal_error ("setting core file size limit to maximum: %m");
1356 #endif
1357 diagnostic_abort_on_error (global_dc);
1361 /* Strip off a legitimate source ending from the input string NAME of
1362 length LEN. Rather than having to know the names used by all of
1363 our front ends, we strip off an ending of a period followed by
1364 up to five characters. (Java uses ".class".) */
1366 void
1367 strip_off_ending (char *name, int len)
1369 int i;
1370 for (i = 2; i < 6 && len > i; i++)
1372 if (name[len - i] == '.')
1374 name[len - i] = '\0';
1375 break;
1380 /* Output a quoted string. */
1382 void
1383 output_quoted_string (FILE *asm_file, const char *string)
1385 #ifdef OUTPUT_QUOTED_STRING
1386 OUTPUT_QUOTED_STRING (asm_file, string);
1387 #else
1388 char c;
1390 putc ('\"', asm_file);
1391 while ((c = *string++) != 0)
1393 if (ISPRINT (c))
1395 if (c == '\"' || c == '\\')
1396 putc ('\\', asm_file);
1397 putc (c, asm_file);
1399 else
1400 fprintf (asm_file, "\\%03o", (unsigned char) c);
1402 putc ('\"', asm_file);
1403 #endif
1406 /* Output a file name in the form wanted by System V. */
1408 void
1409 output_file_directive (FILE *asm_file, const char *input_name)
1411 int len;
1412 const char *na;
1414 if (input_name == NULL)
1415 input_name = "<stdin>";
1417 len = strlen (input_name);
1418 na = input_name + len;
1420 /* NA gets INPUT_NAME sans directory names. */
1421 while (na > input_name)
1423 if (IS_DIR_SEPARATOR (na[-1]))
1424 break;
1425 na--;
1428 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1429 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1430 #else
1431 fprintf (asm_file, "\t.file\t");
1432 output_quoted_string (asm_file, na);
1433 fputc ('\n', asm_file);
1434 #endif
1437 /* Routine to open a dump file. Return true if the dump file is enabled. */
1439 static int
1440 open_dump_file (enum dump_file_index index, tree decl)
1442 char *dump_name;
1443 const char *open_arg;
1444 char seq[16];
1446 if (! dump_file[index].enabled)
1447 return 0;
1449 timevar_push (TV_DUMP);
1450 if (rtl_dump_file != NULL)
1451 fclose (rtl_dump_file);
1453 sprintf (seq, DUMPFILE_FORMAT, index);
1455 if (! dump_file[index].initialized)
1457 /* If we've not initialized the files, do so now. */
1458 if (graph_dump_format != no_graph
1459 && dump_file[index].graph_dump_p)
1461 dump_name = concat (seq, dump_file[index].extension, NULL);
1462 clean_graph_dump_file (dump_base_name, dump_name);
1463 free (dump_name);
1465 dump_file[index].initialized = 1;
1466 open_arg = "w";
1468 else
1469 open_arg = "a";
1471 dump_name = concat (dump_base_name, seq,
1472 dump_file[index].extension, NULL);
1474 rtl_dump_file = fopen (dump_name, open_arg);
1475 if (rtl_dump_file == NULL)
1476 fatal_error ("can't open %s: %m", dump_name);
1478 free (dump_name);
1480 if (decl)
1481 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1482 (*lang_hooks.decl_printable_name) (decl, 2),
1483 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1484 ? " (hot)"
1485 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1486 ? " (unlikely executed)"
1487 : "");
1489 timevar_pop (TV_DUMP);
1490 return 1;
1493 /* Routine to close a dump file. */
1495 static void
1496 close_dump_file (enum dump_file_index index,
1497 void (*func) (FILE *, rtx),
1498 rtx insns)
1500 if (! rtl_dump_file)
1501 return;
1503 timevar_push (TV_DUMP);
1504 if (insns
1505 && graph_dump_format != no_graph
1506 && dump_file[index].graph_dump_p)
1508 char seq[16];
1509 char *suffix;
1511 sprintf (seq, DUMPFILE_FORMAT, index);
1512 suffix = concat (seq, dump_file[index].extension, NULL);
1513 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1514 free (suffix);
1517 if (func && insns)
1518 func (rtl_dump_file, insns);
1520 fflush (rtl_dump_file);
1521 fclose (rtl_dump_file);
1523 rtl_dump_file = NULL;
1524 timevar_pop (TV_DUMP);
1527 /* Do any final processing required for the declarations in VEC, of
1528 which there are LEN. We write out inline functions and variables
1529 that have been deferred until this point, but which are required.
1530 Returns nonzero if anything was put out. */
1533 wrapup_global_declarations (tree *vec, int len)
1535 tree decl;
1536 int i;
1537 int reconsider;
1538 int output_something = 0;
1540 for (i = 0; i < len; i++)
1542 decl = vec[i];
1544 /* We're not deferring this any longer. Assignment is
1545 conditional to avoid needlessly dirtying PCH pages. */
1546 if (DECL_DEFER_OUTPUT (decl) != 0)
1547 DECL_DEFER_OUTPUT (decl) = 0;
1549 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1550 (*lang_hooks.finish_incomplete_decl) (decl);
1553 /* Now emit any global variables or functions that we have been
1554 putting off. We need to loop in case one of the things emitted
1555 here references another one which comes earlier in the list. */
1558 reconsider = 0;
1559 for (i = 0; i < len; i++)
1561 decl = vec[i];
1563 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1564 continue;
1566 /* Don't write out static consts, unless we still need them.
1568 We also keep static consts if not optimizing (for debugging),
1569 unless the user specified -fno-keep-static-consts.
1570 ??? They might be better written into the debug information.
1571 This is possible when using DWARF.
1573 A language processor that wants static constants to be always
1574 written out (even if it is not used) is responsible for
1575 calling rest_of_decl_compilation itself. E.g. the C front-end
1576 calls rest_of_decl_compilation from finish_decl.
1577 One motivation for this is that is conventional in some
1578 environments to write things like:
1579 static const char rcsid[] = "... version string ...";
1580 intending to force the string to be in the executable.
1582 A language processor that would prefer to have unneeded
1583 static constants "optimized away" would just defer writing
1584 them out until here. E.g. C++ does this, because static
1585 constants are often defined in header files.
1587 ??? A tempting alternative (for both C and C++) would be
1588 to force a constant to be written if and only if it is
1589 defined in a main file, as opposed to an include file. */
1591 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1593 bool needed = 1;
1595 if (flag_unit_at_a_time
1596 && cgraph_varpool_node (decl)->finalized)
1597 needed = 0;
1598 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1599 && (TREE_USED (decl)
1600 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1601 /* needed */;
1602 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1603 /* needed */;
1604 else if (DECL_COMDAT (decl))
1605 needed = 0;
1606 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1607 && (optimize || !flag_keep_static_consts
1608 || DECL_ARTIFICIAL (decl)))
1609 needed = 0;
1611 if (needed)
1613 reconsider = 1;
1614 rest_of_decl_compilation (decl, NULL, 1, 1);
1618 if (TREE_CODE (decl) == FUNCTION_DECL
1619 && DECL_INITIAL (decl) != 0
1620 && DECL_SAVED_INSNS (decl) != 0
1621 && DECL_SAVED_INSNS (decl)->saved_for_inline
1622 && (flag_keep_inline_functions
1623 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1624 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1626 reconsider = 1;
1627 output_inline_function (decl);
1631 if (reconsider)
1632 output_something = 1;
1634 while (reconsider);
1636 return output_something;
1639 /* Issue appropriate warnings for the global declarations in VEC (of
1640 which there are LEN). Output debugging information for them. */
1642 void
1643 check_global_declarations (tree *vec, int len)
1645 tree decl;
1646 int i;
1648 for (i = 0; i < len; i++)
1650 decl = vec[i];
1652 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1653 && ! TREE_ASM_WRITTEN (decl))
1654 /* Cancel the RTL for this decl so that, if debugging info
1655 output for global variables is still to come,
1656 this one will be omitted. */
1657 SET_DECL_RTL (decl, NULL_RTX);
1659 /* Warn about any function
1660 declared static but not defined.
1661 We don't warn about variables,
1662 because many programs have static variables
1663 that exist only to get some text into the object file. */
1664 if (TREE_CODE (decl) == FUNCTION_DECL
1665 && (warn_unused_function
1666 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1667 && DECL_INITIAL (decl) == 0
1668 && DECL_EXTERNAL (decl)
1669 && ! DECL_ARTIFICIAL (decl)
1670 && ! TREE_PUBLIC (decl))
1672 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1673 pedwarn ("%J'%F' used but never defined", decl, decl);
1674 else
1675 warning ("%J'%F' declared `static' but never defined", decl, decl);
1676 /* This symbol is effectively an "extern" declaration now. */
1677 TREE_PUBLIC (decl) = 1;
1678 assemble_external (decl);
1681 /* Warn about static fns or vars defined but not used. */
1682 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1683 /* We don't warn about "static const" variables because the
1684 "rcs_id" idiom uses that construction. */
1685 || (warn_unused_variable
1686 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
1687 && ! DECL_IN_SYSTEM_HEADER (decl)
1688 && ! TREE_USED (decl)
1689 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1690 to handle multiple external decls in different scopes. */
1691 && ! TREE_USED (DECL_NAME (decl))
1692 && ! DECL_EXTERNAL (decl)
1693 && ! TREE_PUBLIC (decl)
1694 /* A volatile variable might be used in some non-obvious way. */
1695 && ! TREE_THIS_VOLATILE (decl)
1696 /* Global register variables must be declared to reserve them. */
1697 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1698 /* Otherwise, ask the language. */
1699 && (*lang_hooks.decls.warn_unused_global) (decl))
1700 warning ("%J'%D' defined but not used", decl, decl);
1702 /* Avoid confusing the debug information machinery when there are
1703 errors. */
1704 if (errorcount == 0 && sorrycount == 0)
1706 timevar_push (TV_SYMOUT);
1707 (*debug_hooks->global_decl) (decl);
1708 timevar_pop (TV_SYMOUT);
1713 /* Warn about a use of an identifier which was marked deprecated. */
1714 void
1715 warn_deprecated_use (tree node)
1717 if (node == 0 || !warn_deprecated_decl)
1718 return;
1720 if (DECL_P (node))
1721 warning ("`%s' is deprecated (declared at %s:%d)",
1722 IDENTIFIER_POINTER (DECL_NAME (node)),
1723 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1724 else if (TYPE_P (node))
1726 const char *what = NULL;
1727 tree decl = TYPE_STUB_DECL (node);
1729 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1730 what = IDENTIFIER_POINTER (TYPE_NAME (node));
1731 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1732 && DECL_NAME (TYPE_NAME (node)))
1733 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1735 if (what)
1737 if (decl)
1738 warning ("`%s' is deprecated (declared at %s:%d)", what,
1739 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1740 else
1741 warning ("`%s' is deprecated", what);
1743 else if (decl)
1744 warning ("type is deprecated (declared at %s:%d)",
1745 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1746 else
1747 warning ("type is deprecated");
1751 /* Save the current INPUT_LOCATION on the top entry in the
1752 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1753 INPUT_LOCATION accordingly. */
1755 void
1756 push_srcloc (const char *file, int line)
1758 struct file_stack *fs;
1760 fs = xmalloc (sizeof (struct file_stack));
1761 fs->location = input_location;
1762 fs->next = input_file_stack;
1763 input_filename = file;
1764 input_line = line;
1765 input_file_stack = fs;
1766 input_file_stack_tick++;
1769 /* Pop the top entry off the stack of presently open source files.
1770 Restore the INPUT_LOCATION from the new topmost entry on the
1771 stack. */
1773 void
1774 pop_srcloc (void)
1776 struct file_stack *fs;
1778 fs = input_file_stack;
1779 input_location = fs->location;
1780 input_file_stack = fs->next;
1781 free (fs);
1782 input_file_stack_tick++;
1785 /* Compile an entire translation unit. Write a file of assembly
1786 output and various debugging dumps. */
1788 static void
1789 compile_file (void)
1791 /* Initialize yet another pass. */
1793 init_final (main_input_filename);
1794 coverage_init (aux_base_name);
1796 timevar_push (TV_PARSE);
1798 /* Call the parser, which parses the entire file (calling
1799 rest_of_compilation for each function). */
1800 (*lang_hooks.parse_file) (set_yydebug);
1802 /* In case there were missing block closers,
1803 get us back to the global binding level. */
1804 (*lang_hooks.clear_binding_stack) ();
1806 /* Compilation is now finished except for writing
1807 what's left of the symbol table output. */
1808 timevar_pop (TV_PARSE);
1810 if (flag_syntax_only)
1811 return;
1813 (*lang_hooks.decls.final_write_globals)();
1815 cgraph_varpool_assemble_pending_decls ();
1817 /* This must occur after the loop to output deferred functions.
1818 Else the coverage initializer would not be emitted if all the
1819 functions in this compilation unit were deferred. */
1820 coverage_finish ();
1822 /* Write out any pending weak symbol declarations. */
1824 weak_finish ();
1826 /* Do dbx symbols. */
1827 timevar_push (TV_SYMOUT);
1829 #ifdef DWARF2_UNWIND_INFO
1830 if (dwarf2out_do_frame ())
1831 dwarf2out_frame_finish ();
1832 #endif
1834 (*debug_hooks->finish) (main_input_filename);
1835 timevar_pop (TV_SYMOUT);
1837 /* Output some stuff at end of file if nec. */
1839 dw2_output_indirect_constants ();
1841 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1843 timevar_push (TV_DUMP);
1844 open_dump_file (DFI_bp, NULL);
1846 end_branch_prob ();
1848 close_dump_file (DFI_bp, NULL, NULL_RTX);
1849 timevar_pop (TV_DUMP);
1852 targetm.asm_out.file_end ();
1854 /* Attach a special .ident directive to the end of the file to identify
1855 the version of GCC which compiled this code. The format of the .ident
1856 string is patterned after the ones produced by native SVR4 compilers. */
1857 #ifdef IDENT_ASM_OP
1858 if (!flag_no_ident)
1859 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1860 IDENT_ASM_OP, version_string);
1861 #endif
1863 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1865 timevar_push (TV_DUMP);
1866 dump_combine_total_stats (rtl_dump_file);
1867 close_dump_file (DFI_combine, NULL, NULL_RTX);
1868 timevar_pop (TV_DUMP);
1872 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1873 and TYPE_DECL nodes.
1875 This does nothing for local (non-static) variables, unless the
1876 variable is a register variable with an ASMSPEC. In that case, or
1877 if the variable is not an automatic, it sets up the RTL and
1878 outputs any assembler code (label definition, storage allocation
1879 and initialization).
1881 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1882 the assembler symbol name to be used. TOP_LEVEL is nonzero
1883 if this declaration is not within a function. */
1885 void
1886 rest_of_decl_compilation (tree decl,
1887 const char *asmspec,
1888 int top_level,
1889 int at_end)
1891 /* We deferred calling assemble_alias so that we could collect
1892 other attributes such as visibility. Emit the alias now. */
1894 tree alias;
1895 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1896 if (alias)
1898 alias = TREE_VALUE (TREE_VALUE (alias));
1899 alias = get_identifier (TREE_STRING_POINTER (alias));
1900 assemble_alias (decl, alias);
1904 /* Forward declarations for nested functions are not "external",
1905 but we need to treat them as if they were. */
1906 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1907 || TREE_CODE (decl) == FUNCTION_DECL)
1909 timevar_push (TV_VARCONST);
1911 if (asmspec)
1912 make_decl_rtl (decl, asmspec);
1914 /* Don't output anything when a tentative file-scope definition
1915 is seen. But at end of compilation, do output code for them.
1917 We do output all variables when unit-at-a-time is active and rely on
1918 callgraph code to defer them except for forward declarations
1919 (see gcc.c-torture/compile/920624-1.c) */
1920 if ((at_end
1921 || !DECL_DEFER_OUTPUT (decl)
1922 || (flag_unit_at_a_time && DECL_INITIAL (decl)))
1923 && !DECL_EXTERNAL (decl))
1925 if (flag_unit_at_a_time && !cgraph_global_info_ready
1926 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1927 cgraph_varpool_finalize_decl (decl);
1928 else
1929 assemble_variable (decl, top_level, at_end, 0);
1932 #ifdef ASM_FINISH_DECLARE_OBJECT
1933 if (decl == last_assemble_variable_decl)
1935 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1936 top_level, at_end);
1938 #endif
1940 timevar_pop (TV_VARCONST);
1942 else if (DECL_REGISTER (decl) && asmspec != 0)
1944 if (decode_reg_name (asmspec) >= 0)
1946 SET_DECL_RTL (decl, NULL_RTX);
1947 make_decl_rtl (decl, asmspec);
1949 else
1951 error ("invalid register name `%s' for register variable", asmspec);
1952 DECL_REGISTER (decl) = 0;
1953 if (!top_level)
1954 expand_decl (decl);
1957 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1958 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1959 && TREE_CODE (decl) == TYPE_DECL)
1961 timevar_push (TV_SYMOUT);
1962 dbxout_symbol (decl, 0);
1963 timevar_pop (TV_SYMOUT);
1965 #endif
1966 #ifdef SDB_DEBUGGING_INFO
1967 else if (write_symbols == SDB_DEBUG && top_level
1968 && TREE_CODE (decl) == TYPE_DECL)
1970 timevar_push (TV_SYMOUT);
1971 sdbout_symbol (decl, 0);
1972 timevar_pop (TV_SYMOUT);
1974 #endif
1975 #ifdef DWARF2_DEBUGGING_INFO
1976 else if ((write_symbols == DWARF2_DEBUG
1977 || write_symbols == VMS_AND_DWARF2_DEBUG)
1978 && top_level
1979 && TREE_CODE (decl) == TYPE_DECL)
1981 timevar_push (TV_SYMOUT);
1982 dwarf2out_decl (decl);
1983 timevar_pop (TV_SYMOUT);
1985 #endif
1988 /* Called after finishing a record, union or enumeral type. */
1990 void
1991 rest_of_type_compilation (
1992 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
1993 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
1994 tree type,
1995 int toplev
1996 #else
1997 tree type ATTRIBUTE_UNUSED,
1998 int toplev ATTRIBUTE_UNUSED
1999 #endif
2002 /* Avoid confusing the debug information machinery when there are
2003 errors. */
2004 if (errorcount != 0 || sorrycount != 0)
2005 return;
2007 timevar_push (TV_SYMOUT);
2008 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2009 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2010 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2011 #endif
2012 #ifdef SDB_DEBUGGING_INFO
2013 if (write_symbols == SDB_DEBUG)
2014 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2015 #endif
2016 #ifdef DWARF2_DEBUGGING_INFO
2017 if ((write_symbols == DWARF2_DEBUG
2018 || write_symbols == VMS_AND_DWARF2_DEBUG)
2019 && toplev)
2020 dwarf2out_decl (TYPE_STUB_DECL (type));
2021 #endif
2022 timevar_pop (TV_SYMOUT);
2025 /* Turn the RTL into assembly. */
2026 static void
2027 rest_of_handle_final (tree decl, rtx insns)
2029 timevar_push (TV_FINAL);
2031 rtx x;
2032 const char *fnname;
2034 /* Get the function's name, as described by its RTL. This may be
2035 different from the DECL_NAME name used in the source file. */
2037 x = DECL_RTL (decl);
2038 if (GET_CODE (x) != MEM)
2039 abort ();
2040 x = XEXP (x, 0);
2041 if (GET_CODE (x) != SYMBOL_REF)
2042 abort ();
2043 fnname = XSTR (x, 0);
2045 assemble_start_function (decl, fnname);
2046 final_start_function (insns, asm_out_file, optimize);
2047 final (insns, asm_out_file, optimize, 0);
2048 final_end_function ();
2050 #ifdef IA64_UNWIND_INFO
2051 /* ??? The IA-64 ".handlerdata" directive must be issued before
2052 the ".endp" directive that closes the procedure descriptor. */
2053 output_function_exception_table ();
2054 #endif
2056 assemble_end_function (decl, fnname);
2058 #ifndef IA64_UNWIND_INFO
2059 /* Otherwise, it feels unclean to switch sections in the middle. */
2060 output_function_exception_table ();
2061 #endif
2063 if (! quiet_flag)
2064 fflush (asm_out_file);
2066 /* Release all memory allocated by flow. */
2067 free_basic_block_vars (0);
2069 /* Release all memory held by regsets now. */
2070 regset_release_memory ();
2072 timevar_pop (TV_FINAL);
2074 ggc_collect ();
2077 #ifdef DELAY_SLOTS
2078 /* Run delay slot optimization. */
2079 static void
2080 rest_of_handle_delay_slots (tree decl, rtx insns)
2082 timevar_push (TV_DBR_SCHED);
2083 open_dump_file (DFI_dbr, decl);
2085 dbr_schedule (insns, rtl_dump_file);
2087 close_dump_file (DFI_dbr, print_rtl, insns);
2088 timevar_pop (TV_DBR_SCHED);
2090 ggc_collect ();
2092 #endif
2094 #ifdef STACK_REGS
2095 /* Convert register usage from flat register file usage to a stack
2096 register file. */
2097 static void
2098 rest_of_handle_stack_regs (tree decl, rtx insns)
2100 #if defined (HAVE_ATTR_length)
2101 /* If flow2 creates new instructions which need splitting
2102 and scheduling after reload is not done, they might not be
2103 split until final which doesn't allow splitting
2104 if HAVE_ATTR_length. */
2105 #ifdef INSN_SCHEDULING
2106 if (optimize && !flag_schedule_insns_after_reload)
2107 #else
2108 if (optimize)
2109 #endif
2111 timevar_push (TV_SHORTEN_BRANCH);
2112 split_all_insns (1);
2113 timevar_pop (TV_SHORTEN_BRANCH);
2115 #endif
2117 timevar_push (TV_REG_STACK);
2118 open_dump_file (DFI_stack, decl);
2120 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2122 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2123 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2124 && flag_reorder_blocks)
2126 reorder_basic_blocks ();
2127 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2131 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2132 timevar_pop (TV_REG_STACK);
2134 ggc_collect ();
2136 #endif
2139 /* Machine independent reorg pass. */
2140 static void
2141 rest_of_handle_machine_reorg (tree decl, rtx insns)
2143 timevar_push (TV_MACH_DEP);
2144 open_dump_file (DFI_mach, decl);
2146 (*targetm.machine_dependent_reorg) ();
2148 close_dump_file (DFI_mach, print_rtl, insns);
2149 timevar_pop (TV_MACH_DEP);
2151 ggc_collect ();
2155 /* Run new register allocator. Return TRUE if we must exit
2156 rest_of_compilation upon return. */
2157 static bool
2158 rest_of_handle_new_regalloc (tree decl, rtx insns)
2160 int failure;
2162 delete_trivially_dead_insns (insns, max_reg_num ());
2163 reg_alloc ();
2165 timevar_pop (TV_LOCAL_ALLOC);
2166 if (dump_file[DFI_lreg].enabled)
2168 timevar_push (TV_DUMP);
2170 close_dump_file (DFI_lreg, NULL, NULL);
2171 timevar_pop (TV_DUMP);
2174 /* XXX clean up the whole mess to bring live info in shape again. */
2175 timevar_push (TV_GLOBAL_ALLOC);
2176 open_dump_file (DFI_greg, decl);
2178 build_insn_chain (insns);
2179 failure = reload (insns, 0);
2181 timevar_pop (TV_GLOBAL_ALLOC);
2183 if (dump_file[DFI_greg].enabled)
2185 timevar_push (TV_DUMP);
2187 dump_global_regs (rtl_dump_file);
2189 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2190 timevar_pop (TV_DUMP);
2193 if (failure)
2194 return true;
2196 reload_completed = 1;
2198 return false;
2201 /* Run old register allocator. Return TRUE if we must exit
2202 rest_of_compilation upon return. */
2203 static bool
2204 rest_of_handle_old_regalloc (tree decl, rtx insns)
2206 int failure;
2207 int rebuild_notes;
2209 /* Allocate the reg_renumber array. */
2210 allocate_reg_info (max_regno, FALSE, TRUE);
2212 /* And the reg_equiv_memory_loc array. */
2213 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2215 allocate_initial_values (reg_equiv_memory_loc);
2217 regclass (insns, max_reg_num (), rtl_dump_file);
2218 rebuild_notes = local_alloc ();
2220 timevar_pop (TV_LOCAL_ALLOC);
2222 /* Local allocation may have turned an indirect jump into a direct
2223 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
2224 instructions. */
2225 if (rebuild_notes)
2227 timevar_push (TV_JUMP);
2229 rebuild_jump_labels (insns);
2230 purge_all_dead_edges (0);
2232 timevar_pop (TV_JUMP);
2235 if (dump_file[DFI_lreg].enabled)
2237 timevar_push (TV_DUMP);
2239 dump_flow_info (rtl_dump_file);
2240 dump_local_alloc (rtl_dump_file);
2242 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2243 timevar_pop (TV_DUMP);
2246 ggc_collect ();
2248 timevar_push (TV_GLOBAL_ALLOC);
2249 open_dump_file (DFI_greg, decl);
2251 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2252 pass fixing up any insns that are invalid. */
2254 if (optimize)
2255 failure = global_alloc (rtl_dump_file);
2256 else
2258 build_insn_chain (insns);
2259 failure = reload (insns, 0);
2262 timevar_pop (TV_GLOBAL_ALLOC);
2264 if (dump_file[DFI_greg].enabled)
2266 timevar_push (TV_DUMP);
2268 dump_global_regs (rtl_dump_file);
2270 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2271 timevar_pop (TV_DUMP);
2274 return failure;
2277 /* Run the regrename and cprop passes. */
2278 static void
2279 rest_of_handle_regrename (tree decl, rtx insns)
2281 timevar_push (TV_RENAME_REGISTERS);
2282 open_dump_file (DFI_rnreg, decl);
2284 if (flag_rename_registers)
2285 regrename_optimize ();
2286 if (flag_cprop_registers)
2287 copyprop_hardreg_forward ();
2289 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2290 timevar_pop (TV_RENAME_REGISTERS);
2293 /* Reorder basic blocks. */
2294 static void
2295 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2297 open_dump_file (DFI_bbro, decl);
2299 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2300 splitting possibly introduced more crossjumping opportunities. */
2301 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2302 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2304 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2305 tracer ();
2306 if (flag_reorder_blocks)
2307 reorder_basic_blocks ();
2308 if (flag_reorder_blocks
2309 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2310 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2312 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2315 #ifdef INSN_SCHEDULING
2316 /* Run instruction scheduler. */
2317 static void
2318 rest_of_handle_sched (tree decl, rtx insns)
2320 timevar_push (TV_SCHED);
2322 /* Print function header into sched dump now
2323 because doing the sched analysis makes some of the dump. */
2324 if (optimize > 0 && flag_schedule_insns)
2326 open_dump_file (DFI_sched, decl);
2328 /* Do control and data sched analysis,
2329 and write some of the results to dump file. */
2331 schedule_insns (rtl_dump_file);
2333 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2335 timevar_pop (TV_SCHED);
2337 ggc_collect ();
2340 /* Run second scheduling pass after reload. */
2341 static void
2342 rest_of_handle_sched2 (tree decl, rtx insns)
2344 timevar_push (TV_SCHED2);
2345 open_dump_file (DFI_sched2, decl);
2347 /* Do control and data sched analysis again,
2348 and write some more of the results to dump file. */
2350 split_all_insns (1);
2352 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2354 schedule_ebbs (rtl_dump_file);
2355 /* No liveness updating code yet, but it should be easy to do.
2356 reg-stack recompute the liveness when needed for now. */
2357 count_or_remove_death_notes (NULL, 1);
2358 cleanup_cfg (CLEANUP_EXPENSIVE);
2360 else
2361 schedule_insns (rtl_dump_file);
2363 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2364 timevar_pop (TV_SCHED2);
2366 ggc_collect ();
2368 #endif
2370 /* Register allocation pre-pass, to reduce number of moves necessary
2371 for two-address machines. */
2372 static void
2373 rest_of_handle_regmove (tree decl, rtx insns)
2375 timevar_push (TV_REGMOVE);
2376 open_dump_file (DFI_regmove, decl);
2378 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2380 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2381 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2382 timevar_pop (TV_REGMOVE);
2384 ggc_collect ();
2387 /* Run tracer. */
2388 static void
2389 rest_of_handle_tracer (tree decl, rtx insns)
2391 open_dump_file (DFI_tracer, decl);
2392 if (rtl_dump_file)
2393 dump_flow_info (rtl_dump_file);
2394 tracer ();
2395 cleanup_cfg (CLEANUP_EXPENSIVE);
2396 reg_scan (insns, max_reg_num (), 0);
2397 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2400 /* If-conversion and CFG cleanup. */
2401 static void
2402 rest_of_handle_if_conversion (tree decl, rtx insns)
2404 open_dump_file (DFI_ce1, decl);
2405 if (flag_if_conversion)
2407 timevar_push (TV_IFCVT);
2408 if (rtl_dump_file)
2409 dump_flow_info (rtl_dump_file);
2410 cleanup_cfg (CLEANUP_EXPENSIVE);
2411 reg_scan (insns, max_reg_num (), 0);
2412 if_convert (0);
2413 timevar_pop (TV_IFCVT);
2415 timevar_push (TV_JUMP);
2416 cleanup_cfg (CLEANUP_EXPENSIVE);
2417 reg_scan (insns, max_reg_num (), 0);
2418 timevar_pop (TV_JUMP);
2419 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2422 /* Rerun if-conversion, as combine may have simplified things enough
2423 to now meet sequence length restrictions. */
2424 static void
2425 rest_of_handle_if_after_combine (tree decl, rtx insns)
2427 timevar_push (TV_IFCVT);
2428 open_dump_file (DFI_ce2, decl);
2430 no_new_pseudos = 0;
2431 if_convert (1);
2432 no_new_pseudos = 1;
2434 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2435 timevar_pop (TV_IFCVT);
2438 static void
2439 rest_of_handle_web (tree decl, rtx insns)
2441 open_dump_file (DFI_web, decl);
2442 timevar_push (TV_WEB);
2443 web_main ();
2444 delete_trivially_dead_insns (insns, max_reg_num ());
2445 cleanup_cfg (CLEANUP_EXPENSIVE);
2447 timevar_pop (TV_WEB);
2448 close_dump_file (DFI_web, print_rtl_with_bb, insns);
2449 reg_scan (get_insns (), max_reg_num (), 0);
2452 /* Do branch profiling and static profile estimation passes. */
2453 static void
2454 rest_of_handle_branch_prob (tree decl, rtx insns)
2456 struct loops loops;
2458 timevar_push (TV_BRANCH_PROB);
2459 open_dump_file (DFI_bp, decl);
2461 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2462 branch_prob ();
2464 /* Discover and record the loop depth at the head of each basic
2465 block. The loop infrastructure does the real job for us. */
2466 flow_loops_find (&loops, LOOP_TREE);
2468 if (rtl_dump_file)
2469 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2471 /* Estimate using heuristics if no profiling info is available. */
2472 if (flag_guess_branch_prob)
2473 estimate_probability (&loops);
2475 flow_loops_free (&loops);
2476 free_dominance_info (CDI_DOMINATORS);
2477 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2478 timevar_pop (TV_BRANCH_PROB);
2481 /* Do optimizations based on expression value profiles. */
2482 static void
2483 rest_of_handle_value_profile_transformations (tree decl, rtx insns)
2485 open_dump_file (DFI_vpt, decl);
2486 timevar_push (TV_VPT);
2488 if (value_profile_transformations ())
2489 cleanup_cfg (CLEANUP_EXPENSIVE);
2491 timevar_pop (TV_VPT);
2492 close_dump_file (DFI_vpt, print_rtl_with_bb, insns);
2495 /* Do control and data flow analysis; write some of the results to the
2496 dump file. */
2497 static void
2498 rest_of_handle_cfg (tree decl, rtx insns)
2500 open_dump_file (DFI_cfg, decl);
2501 if (rtl_dump_file)
2502 dump_flow_info (rtl_dump_file);
2503 if (optimize)
2504 cleanup_cfg (CLEANUP_EXPENSIVE
2505 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2507 /* It may make more sense to mark constant functions after dead code is
2508 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2509 may insert code making function non-constant, but we still must consider
2510 it as constant, otherwise -fbranch-probabilities will not read data back.
2512 life_analysis rarely eliminates modification of external memory.
2514 if (optimize)
2516 /* Alias analysis depends on this information and mark_constant_function
2517 depends on alias analysis. */
2518 reg_scan (insns, max_reg_num (), 1);
2519 mark_constant_function ();
2522 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2525 /* Purge addressofs. */
2526 static void
2527 rest_of_handle_addressof (tree decl, rtx insns)
2529 open_dump_file (DFI_addressof, decl);
2531 purge_addressof (insns);
2532 if (optimize && purge_all_dead_edges (0))
2533 delete_unreachable_blocks ();
2534 reg_scan (insns, max_reg_num (), 1);
2536 close_dump_file (DFI_addressof, print_rtl, insns);
2539 /* We may have potential sibling or tail recursion sites. Select one
2540 (of possibly multiple) methods of performing the call. */
2541 static void
2542 rest_of_handle_sibling_calls (rtx insns)
2544 rtx insn;
2545 optimize_sibling_and_tail_recursive_calls ();
2547 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2548 free_bb_for_insn ();
2549 find_exception_handler_labels ();
2550 rebuild_jump_labels (insns);
2551 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2553 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2554 notes before simplifying cfg and we must do lowering after sibcall
2555 that unhides parts of RTL chain and cleans up the CFG.
2557 Until sibcall is replaced by tree-level optimizer, lets just
2558 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2559 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2560 if (GET_CODE (insn) == NOTE
2561 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2562 delete_insn (insn);
2564 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2567 /* Perform jump bypassing and control flow optimizations. */
2568 static void
2569 rest_of_handle_jump_bypass (tree decl, rtx insns)
2571 timevar_push (TV_BYPASS);
2572 open_dump_file (DFI_bypass, decl);
2574 cleanup_cfg (CLEANUP_EXPENSIVE);
2575 reg_scan (insns, max_reg_num (), 1);
2577 if (bypass_jumps (rtl_dump_file))
2579 rebuild_jump_labels (insns);
2580 cleanup_cfg (CLEANUP_EXPENSIVE);
2581 delete_trivially_dead_insns (insns, max_reg_num ());
2584 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2585 timevar_pop (TV_BYPASS);
2587 ggc_collect ();
2589 #ifdef ENABLE_CHECKING
2590 verify_flow_info ();
2591 #endif
2594 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2595 if we must exit rest_of_compilation upon return. */
2596 static bool
2597 rest_of_handle_inlining (tree decl)
2599 rtx insns;
2600 int inlinable = 0;
2601 tree parent;
2602 const char *lose;
2604 /* If we are reconsidering an inline function at the end of
2605 compilation, skip the stuff for making it inline. */
2606 if (cfun->rtl_inline_init)
2607 return 0;
2608 cfun->rtl_inline_init = 1;
2610 /* If this is nested inside an inlined external function, pretend
2611 it was only declared. Since we cannot inline such functions,
2612 generating code for this one is not only not necessary but will
2613 confuse some debugging output writers. */
2614 for (parent = DECL_CONTEXT (current_function_decl);
2615 parent != NULL_TREE;
2616 parent = get_containing_scope (parent))
2617 if (TREE_CODE (parent) == FUNCTION_DECL
2618 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2620 DECL_INITIAL (decl) = 0;
2621 return true;
2623 else if (TYPE_P (parent))
2624 /* A function in a local class should be treated normally. */
2625 break;
2627 /* If requested, consider whether to make this function inline. */
2628 if ((DECL_INLINE (decl) && !flag_no_inline)
2629 || flag_inline_functions)
2631 timevar_push (TV_INTEGRATION);
2632 lose = function_cannot_inline_p (decl);
2633 timevar_pop (TV_INTEGRATION);
2634 if (lose || ! optimize)
2636 if (warn_inline && lose && DECL_INLINE (decl))
2638 char *msg = concat ("%J", lose, NULL);
2639 warning (msg, decl);
2640 free (msg);
2642 DECL_ABSTRACT_ORIGIN (decl) = 0;
2643 /* Don't really compile an extern inline function.
2644 If we can't make it inline, pretend
2645 it was only declared. */
2646 if (DECL_EXTERNAL (decl))
2648 DECL_INITIAL (decl) = 0;
2649 return true;
2652 else
2653 inlinable = DECL_INLINE (decl) = 1;
2656 insns = get_insns ();
2658 /* Dump the rtl code if we are dumping rtl. */
2660 if (open_dump_file (DFI_rtl, decl))
2662 if (DECL_SAVED_INSNS (decl) && DECL_SAVED_INSNS (decl)->saved_for_inline)
2663 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2664 close_dump_file (DFI_rtl, print_rtl, insns);
2667 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2668 sorts of eh initialization. Delay this until after the
2669 initial rtl dump so that we can see the original nesting. */
2670 convert_from_eh_region_ranges ();
2672 /* If function is inline, and we don't yet know whether to
2673 compile it by itself, defer decision till end of compilation.
2674 wrapup_global_declarations will (indirectly) call
2675 rest_of_compilation again for those functions that need to
2676 be output. Also defer those functions that we are supposed
2677 to defer. */
2679 if (inlinable
2680 || (DECL_INLINE (decl)
2681 && flag_inline_functions
2682 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2683 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2684 && ! flag_keep_inline_functions)
2685 || DECL_EXTERNAL (decl))))
2686 DECL_DEFER_OUTPUT (decl) = 1;
2688 if (DECL_INLINE (decl))
2689 /* DWARF wants separate debugging info for abstract and
2690 concrete instances of all inline functions, including those
2691 declared inline but not inlined, and those inlined even
2692 though they weren't declared inline. Conveniently, that's
2693 what DECL_INLINE means at this point. */
2694 (*debug_hooks->deferred_inline_function) (decl);
2696 if (DECL_DEFER_OUTPUT (decl))
2698 /* If -Wreturn-type, we have to do a bit of compilation. We just
2699 want to call cleanup the cfg to figure out whether or not we can
2700 fall off the end of the function; we do the minimum amount of
2701 work necessary to make that safe. */
2702 if (warn_return_type)
2704 int saved_optimize = optimize;
2706 optimize = 0;
2707 rebuild_jump_labels (insns);
2708 find_exception_handler_labels ();
2709 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2710 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2711 optimize = saved_optimize;
2713 /* CFG is no longer maintained up-to-date. */
2714 free_bb_for_insn ();
2717 set_nothrow_function_flags ();
2718 if (current_function_nothrow)
2719 /* Now we know that this can't throw; set the flag for the benefit
2720 of other functions later in this translation unit. */
2721 TREE_NOTHROW (current_function_decl) = 1;
2723 timevar_push (TV_INTEGRATION);
2724 save_for_inline (decl);
2725 timevar_pop (TV_INTEGRATION);
2726 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2727 return true;
2730 /* If specified extern inline but we aren't inlining it, we are
2731 done. This goes for anything that gets here with DECL_EXTERNAL
2732 set, not just things with DECL_INLINE. */
2733 return (bool) DECL_EXTERNAL (decl);
2736 /* Try to identify useless null pointer tests and delete them. */
2737 static void
2738 rest_of_handle_null_pointer (tree decl, rtx insns)
2740 open_dump_file (DFI_null, decl);
2741 if (rtl_dump_file)
2742 dump_flow_info (rtl_dump_file);
2744 if (delete_null_pointer_checks (insns))
2745 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2747 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2750 /* Try combining insns through substitution. */
2751 static void
2752 rest_of_handle_combine (tree decl, rtx insns)
2754 int rebuild_jump_labels_after_combine = 0;
2756 timevar_push (TV_COMBINE);
2757 open_dump_file (DFI_combine, decl);
2759 rebuild_jump_labels_after_combine
2760 = combine_instructions (insns, max_reg_num ());
2762 /* Combining insns may have turned an indirect jump into a
2763 direct jump. Rebuild the JUMP_LABEL fields of jumping
2764 instructions. */
2765 if (rebuild_jump_labels_after_combine)
2767 timevar_push (TV_JUMP);
2768 rebuild_jump_labels (insns);
2769 timevar_pop (TV_JUMP);
2771 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2774 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2775 timevar_pop (TV_COMBINE);
2777 ggc_collect ();
2780 /* Perform life analysis. */
2781 static void
2782 rest_of_handle_life (tree decl, rtx insns)
2784 open_dump_file (DFI_life, decl);
2785 regclass_init ();
2787 #ifdef ENABLE_CHECKING
2788 verify_flow_info ();
2789 #endif
2790 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2791 if (optimize)
2792 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2793 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2794 timevar_pop (TV_FLOW);
2796 if (warn_uninitialized)
2798 uninitialized_vars_warning (DECL_INITIAL (decl));
2799 if (extra_warnings)
2800 setjmp_args_warning ();
2803 if (optimize)
2805 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2807 /* Insns were inserted, and possibly pseudos created, so
2808 things might look a bit different. */
2809 insns = get_insns ();
2810 allocate_reg_life_data ();
2811 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2812 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2816 no_new_pseudos = 1;
2818 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2820 ggc_collect ();
2823 /* Perform common subexpression elimination. Nonzero value from
2824 `cse_main' means that jumps were simplified and some code may now
2825 be unreachable, so do jump optimization again. */
2826 static void
2827 rest_of_handle_cse (tree decl, rtx insns)
2829 int tem;
2831 open_dump_file (DFI_cse, decl);
2832 if (rtl_dump_file)
2833 dump_flow_info (rtl_dump_file);
2834 timevar_push (TV_CSE);
2836 reg_scan (insns, max_reg_num (), 1);
2838 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2839 if (tem)
2840 rebuild_jump_labels (insns);
2841 if (purge_all_dead_edges (0))
2842 delete_unreachable_blocks ();
2844 delete_trivially_dead_insns (insns, max_reg_num ());
2846 /* If we are not running more CSE passes, then we are no longer
2847 expecting CSE to be run. But always rerun it in a cheap mode. */
2848 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2850 if (tem || optimize > 1)
2851 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2852 /* Try to identify useless null pointer tests and delete them. */
2853 if (flag_delete_null_pointer_checks)
2855 timevar_push (TV_JUMP);
2857 if (delete_null_pointer_checks (insns))
2858 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2859 timevar_pop (TV_JUMP);
2862 /* The second pass of jump optimization is likely to have
2863 removed a bunch more instructions. */
2864 renumber_insns (rtl_dump_file);
2866 timevar_pop (TV_CSE);
2867 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2870 /* Run second CSE pass after loop optimizations. */
2871 static void
2872 rest_of_handle_cse2 (tree decl, rtx insns)
2874 int tem;
2876 timevar_push (TV_CSE2);
2877 open_dump_file (DFI_cse2, decl);
2878 if (rtl_dump_file)
2879 dump_flow_info (rtl_dump_file);
2880 /* CFG is no longer maintained up-to-date. */
2881 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2882 purge_all_dead_edges (0);
2883 delete_trivially_dead_insns (insns, max_reg_num ());
2885 if (tem)
2887 timevar_push (TV_JUMP);
2888 rebuild_jump_labels (insns);
2889 cleanup_cfg (CLEANUP_EXPENSIVE);
2890 timevar_pop (TV_JUMP);
2892 reg_scan (insns, max_reg_num (), 0);
2893 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2894 ggc_collect ();
2895 timevar_pop (TV_CSE2);
2898 /* Perform global cse. */
2899 static void
2900 rest_of_handle_gcse (tree decl, rtx insns)
2902 int save_csb, save_cfj;
2903 int tem2 = 0, tem;
2905 timevar_push (TV_GCSE);
2906 open_dump_file (DFI_gcse, decl);
2908 tem = gcse_main (insns, rtl_dump_file);
2909 rebuild_jump_labels (insns);
2910 delete_trivially_dead_insns (insns, max_reg_num ());
2912 save_csb = flag_cse_skip_blocks;
2913 save_cfj = flag_cse_follow_jumps;
2914 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2916 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2917 if (current_function_calls_constant_p)
2918 purge_builtin_constant_p ();
2920 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2921 by gcse. */
2922 if (flag_expensive_optimizations)
2924 timevar_push (TV_CSE);
2925 reg_scan (insns, max_reg_num (), 1);
2926 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2927 purge_all_dead_edges (0);
2928 delete_trivially_dead_insns (insns, max_reg_num ());
2929 timevar_pop (TV_CSE);
2930 cse_not_expected = !flag_rerun_cse_after_loop;
2933 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2934 things up. Then possibly re-run CSE again. */
2935 while (tem || tem2)
2937 tem = tem2 = 0;
2938 timevar_push (TV_JUMP);
2939 rebuild_jump_labels (insns);
2940 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2941 timevar_pop (TV_JUMP);
2943 if (flag_expensive_optimizations)
2945 timevar_push (TV_CSE);
2946 reg_scan (insns, max_reg_num (), 1);
2947 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2948 purge_all_dead_edges (0);
2949 delete_trivially_dead_insns (insns, max_reg_num ());
2950 timevar_pop (TV_CSE);
2954 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2955 timevar_pop (TV_GCSE);
2957 ggc_collect ();
2958 flag_cse_skip_blocks = save_csb;
2959 flag_cse_follow_jumps = save_cfj;
2960 #ifdef ENABLE_CHECKING
2961 verify_flow_info ();
2962 #endif
2965 /* Move constant computations out of loops. */
2966 static void
2967 rest_of_handle_loop_optimize (tree decl, rtx insns)
2969 int do_unroll, do_prefetch;
2971 timevar_push (TV_LOOP);
2972 delete_dead_jumptables ();
2973 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2974 open_dump_file (DFI_loop, decl);
2976 /* CFG is no longer maintained up-to-date. */
2977 free_bb_for_insn ();
2979 if (flag_unroll_loops)
2980 do_unroll = LOOP_AUTO_UNROLL; /* Having two unrollers is useless. */
2981 else
2982 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
2983 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
2985 if (flag_rerun_loop_opt)
2987 cleanup_barriers ();
2989 /* We only want to perform unrolling once. */
2990 loop_optimize (insns, rtl_dump_file, do_unroll);
2991 do_unroll = 0;
2993 /* The first call to loop_optimize makes some instructions
2994 trivially dead. We delete those instructions now in the
2995 hope that doing so will make the heuristics in loop work
2996 better and possibly speed up compilation. */
2997 delete_trivially_dead_insns (insns, max_reg_num ());
2999 /* The regscan pass is currently necessary as the alias
3000 analysis code depends on this information. */
3001 reg_scan (insns, max_reg_num (), 1);
3003 cleanup_barriers ();
3004 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3006 /* Loop can create trivially dead instructions. */
3007 delete_trivially_dead_insns (insns, max_reg_num ());
3008 close_dump_file (DFI_loop, print_rtl, insns);
3009 timevar_pop (TV_LOOP);
3010 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3012 ggc_collect ();
3015 /* Perform loop optimizations. It might be better to do them a bit
3016 sooner, but we want the profile feedback to work more
3017 efficiently. */
3018 static void
3019 rest_of_handle_loop2 (tree decl, rtx insns)
3021 struct loops *loops;
3022 timevar_push (TV_LOOP);
3023 open_dump_file (DFI_loop2, decl);
3024 if (rtl_dump_file)
3025 dump_flow_info (rtl_dump_file);
3027 loops = loop_optimizer_init (rtl_dump_file);
3029 if (loops)
3031 /* The optimizations: */
3032 if (flag_unswitch_loops)
3033 unswitch_loops (loops);
3035 if (flag_peel_loops || flag_unroll_loops)
3036 unroll_and_peel_loops (loops,
3037 (flag_peel_loops ? UAP_PEEL : 0) |
3038 (flag_unroll_loops ? UAP_UNROLL : 0) |
3039 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3041 loop_optimizer_finalize (loops, rtl_dump_file);
3044 cleanup_cfg (CLEANUP_EXPENSIVE);
3045 delete_trivially_dead_insns (insns, max_reg_num ());
3046 reg_scan (insns, max_reg_num (), 0);
3047 if (rtl_dump_file)
3048 dump_flow_info (rtl_dump_file);
3049 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3050 timevar_pop (TV_LOOP);
3051 ggc_collect ();
3054 /* This is called from finish_function (within langhooks.parse_file)
3055 after each top-level definition is parsed.
3056 It is supposed to compile that function or variable
3057 and output the assembler code for it.
3058 After we return, the tree storage is freed. */
3060 void
3061 rest_of_compilation (tree decl)
3063 rtx insns;
3065 timevar_push (TV_REST_OF_COMPILATION);
3067 /* Register rtl specific functions for cfg. */
3068 rtl_register_cfg_hooks ();
3070 /* Now that we're out of the frontend, we shouldn't have any more
3071 CONCATs anywhere. */
3072 generating_concat_p = 0;
3074 /* When processing delayed functions, prepare_function_start() won't
3075 have been run to re-initialize it. */
3076 cse_not_expected = ! optimize;
3078 /* First, make sure that NOTE_BLOCK is set correctly for each
3079 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3080 if (!cfun->x_whole_function_mode_p)
3081 identify_blocks ();
3083 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3084 tree in sensible shape. So, we just recalculate it here. */
3085 if (cfun->x_whole_function_mode_p)
3086 reorder_blocks ();
3088 init_flow ();
3090 if (rest_of_handle_inlining (decl))
3091 goto exit_rest_of_compilation;
3093 /* If we're emitting a nested function, make sure its parent gets
3094 emitted as well. Doing otherwise confuses debug info. */
3096 tree parent;
3097 for (parent = DECL_CONTEXT (current_function_decl);
3098 parent != NULL_TREE;
3099 parent = get_containing_scope (parent))
3100 if (TREE_CODE (parent) == FUNCTION_DECL)
3101 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3104 /* We are now committed to emitting code for this function. Do any
3105 preparation, such as emitting abstract debug info for the inline
3106 before it gets mangled by optimization. */
3107 if (cgraph_function_possibly_inlined_p (decl))
3108 (*debug_hooks->outlining_inline_function) (decl);
3110 /* Remove any notes we don't need. That will make iterating
3111 over the instruction sequence faster, and allow the garbage
3112 collector to reclaim the memory used by the notes. */
3113 remove_unnecessary_notes ();
3114 reorder_blocks ();
3116 ggc_collect ();
3118 /* Initialize some variables used by the optimizers. */
3119 init_function_for_compilation ();
3121 if (! DECL_DEFER_OUTPUT (decl))
3122 TREE_ASM_WRITTEN (decl) = 1;
3124 /* Now that integrate will no longer see our rtl, we need not
3125 distinguish between the return value of this function and the
3126 return value of called functions. Also, we can remove all SETs
3127 of subregs of hard registers; they are only here because of
3128 integrate. Also, we can now initialize pseudos intended to
3129 carry magic hard reg data throughout the function. */
3130 rtx_equal_function_value_matters = 0;
3131 purge_hard_subreg_sets (get_insns ());
3133 /* Early return if there were errors. We can run afoul of our
3134 consistency checks, and there's not really much point in fixing them.
3135 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3136 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3137 || errorcount || sorrycount)
3138 goto exit_rest_of_compilation;
3140 timevar_push (TV_JUMP);
3141 open_dump_file (DFI_sibling, decl);
3142 insns = get_insns ();
3143 rebuild_jump_labels (insns);
3144 find_exception_handler_labels ();
3145 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3147 delete_unreachable_blocks ();
3149 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3150 if (flag_guess_branch_prob)
3152 timevar_push (TV_BRANCH_PROB);
3153 note_prediction_to_br_prob ();
3154 timevar_pop (TV_BRANCH_PROB);
3157 if (flag_optimize_sibling_calls)
3158 rest_of_handle_sibling_calls (insns);
3160 /* We have to issue these warnings now already, because CFG cleanups
3161 further down may destroy the required information. However, this
3162 must be done after the sibcall optimization pass because the barrier
3163 emitted for noreturn calls that are candidate for the optimization
3164 is folded into the CALL_PLACEHOLDER until after this pass, so the
3165 CFG is inaccurate. */
3166 check_function_return_warnings ();
3168 timevar_pop (TV_JUMP);
3170 insn_locators_initialize ();
3171 /* Complete generation of exception handling code. */
3172 if (doing_eh (0))
3174 timevar_push (TV_JUMP);
3175 open_dump_file (DFI_eh, decl);
3177 finish_eh_generation ();
3179 close_dump_file (DFI_eh, print_rtl, get_insns ());
3180 timevar_pop (TV_JUMP);
3183 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3184 generation, which might create new sets. */
3185 emit_initial_value_sets ();
3187 #ifdef FINALIZE_PIC
3188 /* If we are doing position-independent code generation, now
3189 is the time to output special prologues and epilogues.
3190 We do not want to do this earlier, because it just clutters
3191 up inline functions with meaningless insns. */
3192 if (flag_pic)
3193 FINALIZE_PIC;
3194 #endif
3196 insns = get_insns ();
3198 /* Copy any shared structure that should not be shared. */
3199 unshare_all_rtl (current_function_decl, insns);
3201 #ifdef SETJMP_VIA_SAVE_AREA
3202 /* This must be performed before virtual register instantiation.
3203 Please be aware the everything in the compiler that can look
3204 at the RTL up to this point must understand that REG_SAVE_AREA
3205 is just like a use of the REG contained inside. */
3206 if (current_function_calls_alloca)
3207 optimize_save_area_alloca (insns);
3208 #endif
3210 /* Instantiate all virtual registers. */
3211 instantiate_virtual_regs (current_function_decl, insns);
3213 open_dump_file (DFI_jump, decl);
3215 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3216 are initialized and to compute whether control can drop off the end
3217 of the function. */
3219 timevar_push (TV_JUMP);
3220 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3221 before jump optimization switches branch directions. */
3222 if (flag_guess_branch_prob)
3223 expected_value_to_br_prob ();
3225 reg_scan (insns, max_reg_num (), 0);
3226 rebuild_jump_labels (insns);
3227 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3228 delete_trivially_dead_insns (insns, max_reg_num ());
3229 if (rtl_dump_file)
3230 dump_flow_info (rtl_dump_file);
3231 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3232 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3234 if (optimize)
3236 free_bb_for_insn ();
3237 copy_loop_headers (insns);
3238 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3240 purge_line_number_notes (insns);
3242 timevar_pop (TV_JUMP);
3243 close_dump_file (DFI_jump, print_rtl, insns);
3245 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3246 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3247 goto exit_rest_of_compilation;
3249 timevar_push (TV_JUMP);
3251 if (optimize)
3252 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3254 if (flag_delete_null_pointer_checks)
3255 rest_of_handle_null_pointer (decl, insns);
3257 /* Jump optimization, and the removal of NULL pointer checks, may
3258 have reduced the number of instructions substantially. CSE, and
3259 future passes, allocate arrays whose dimensions involve the
3260 maximum instruction UID, so if we can reduce the maximum UID
3261 we'll save big on memory. */
3262 renumber_insns (rtl_dump_file);
3263 timevar_pop (TV_JUMP);
3265 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3267 ggc_collect ();
3269 if (optimize > 0)
3270 rest_of_handle_cse (decl, insns);
3272 rest_of_handle_addressof (decl, insns);
3274 ggc_collect ();
3276 if (optimize > 0)
3278 if (flag_gcse)
3279 rest_of_handle_gcse (decl, insns);
3281 if (flag_loop_optimize)
3282 rest_of_handle_loop_optimize (decl, insns);
3285 timevar_push (TV_FLOW);
3287 rest_of_handle_cfg (decl, insns);
3289 if (optimize > 0
3290 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3292 rest_of_handle_branch_prob (decl, insns);
3294 if (flag_branch_probabilities
3295 && flag_profile_values
3296 && flag_value_profile_transformations)
3297 rest_of_handle_value_profile_transformations (decl, insns);
3299 /* Remove the death notes created for vpt. */
3300 if (flag_profile_values)
3301 count_or_remove_death_notes (NULL, 1);
3304 if (optimize > 0)
3305 rest_of_handle_if_conversion (decl, insns);
3307 if (flag_tracer)
3308 rest_of_handle_tracer (decl, insns);
3310 if (optimize > 0)
3312 if (flag_unswitch_loops
3313 || flag_peel_loops
3314 || flag_unroll_loops)
3315 rest_of_handle_loop2 (decl, insns);
3317 if (flag_gcse)
3318 rest_of_handle_jump_bypass (decl, insns);
3321 if (flag_web)
3322 rest_of_handle_web (decl, insns);
3324 if (flag_rerun_cse_after_loop)
3325 rest_of_handle_cse2 (decl, insns);
3327 cse_not_expected = 1;
3329 rest_of_handle_life (decl, insns);
3331 if (optimize > 0)
3332 rest_of_handle_combine (decl, insns);
3334 if (flag_if_conversion)
3335 rest_of_handle_if_after_combine (decl, insns);
3337 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3338 rest_of_handle_regmove (decl, insns);
3340 /* Do unconditional splitting before register allocation to allow machine
3341 description to add extra information not needed previously. */
3342 split_all_insns (1);
3344 #ifdef OPTIMIZE_MODE_SWITCHING
3345 timevar_push (TV_MODE_SWITCH);
3347 no_new_pseudos = 0;
3348 optimize_mode_switching (NULL);
3349 no_new_pseudos = 1;
3351 timevar_pop (TV_MODE_SWITCH);
3352 #endif
3354 /* Any of the several passes since flow1 will have munged register
3355 lifetime data a bit. We need it to be up to date for scheduling
3356 (see handling of reg_known_equiv in init_alias_analysis). */
3357 recompute_reg_usage (insns, !optimize_size);
3359 #ifdef INSN_SCHEDULING
3360 rest_of_handle_sched (decl, insns);
3361 #endif
3363 /* Determine if the current function is a leaf before running reload
3364 since this can impact optimizations done by the prologue and
3365 epilogue thus changing register elimination offsets. */
3366 current_function_is_leaf = leaf_function_p ();
3368 timevar_push (TV_LOCAL_ALLOC);
3369 open_dump_file (DFI_lreg, decl);
3371 if (flag_new_regalloc)
3373 if (rest_of_handle_new_regalloc (decl, insns))
3374 goto exit_rest_of_compilation;
3376 else
3378 if (rest_of_handle_old_regalloc (decl, insns))
3379 goto exit_rest_of_compilation;
3382 ggc_collect ();
3384 open_dump_file (DFI_postreload, decl);
3386 /* Do a very simple CSE pass over just the hard registers. */
3387 if (optimize > 0)
3389 timevar_push (TV_RELOAD_CSE_REGS);
3390 reload_cse_regs (insns);
3391 /* reload_cse_regs can eliminate potentially-trapping MEMs.
3392 Remove any EH edges associated with them. */
3393 if (flag_non_call_exceptions)
3394 purge_all_dead_edges (0);
3395 timevar_pop (TV_RELOAD_CSE_REGS);
3398 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3400 /* Re-create the death notes which were deleted during reload. */
3401 timevar_push (TV_FLOW2);
3402 open_dump_file (DFI_flow2, decl);
3404 #ifdef ENABLE_CHECKING
3405 verify_flow_info ();
3406 #endif
3408 /* If optimizing, then go ahead and split insns now. */
3409 #ifndef STACK_REGS
3410 if (optimize > 0)
3411 #endif
3412 split_all_insns (0);
3414 if (flag_branch_target_load_optimize)
3416 open_dump_file (DFI_branch_target_load, decl);
3418 branch_target_load_optimize (insns, false);
3420 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3422 ggc_collect ();
3425 if (optimize)
3426 cleanup_cfg (CLEANUP_EXPENSIVE);
3428 /* On some machines, the prologue and epilogue code, or parts thereof,
3429 can be represented as RTL. Doing so lets us schedule insns between
3430 it and the rest of the code and also allows delayed branch
3431 scheduling to operate in the epilogue. */
3432 thread_prologue_and_epilogue_insns (insns);
3433 epilogue_completed = 1;
3435 if (optimize)
3437 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3438 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3439 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3441 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3442 even for machines with possibly nonzero RETURN_POPS_ARGS
3443 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3444 push instructions will have popping returns. */
3445 #ifndef PUSH_ROUNDING
3446 if (!ACCUMULATE_OUTGOING_ARGS)
3447 #endif
3448 combine_stack_adjustments ();
3450 ggc_collect ();
3453 flow2_completed = 1;
3455 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3456 timevar_pop (TV_FLOW2);
3458 #ifdef HAVE_peephole2
3459 if (optimize > 0 && flag_peephole2)
3461 timevar_push (TV_PEEPHOLE2);
3462 open_dump_file (DFI_peephole2, decl);
3464 peephole2_optimize (rtl_dump_file);
3466 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3467 timevar_pop (TV_PEEPHOLE2);
3469 #endif
3471 if (flag_if_conversion2)
3473 timevar_push (TV_IFCVT2);
3474 open_dump_file (DFI_ce3, decl);
3476 if_convert (1);
3478 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3479 timevar_pop (TV_IFCVT2);
3482 if (optimize > 0)
3484 if (flag_rename_registers || flag_cprop_registers)
3485 rest_of_handle_regrename (decl, insns);
3487 rest_of_handle_reorder_blocks (decl, insns);
3490 if (flag_branch_target_load_optimize2)
3492 /* Leave this a warning for now so that it is possible to experiment
3493 with running this pass twice. In 3.6, we should either make this
3494 an error, or use separate dump files. */
3495 if (flag_branch_target_load_optimize)
3496 warning ("branch target register load optimization is not intended "
3497 "to be run twice");
3499 open_dump_file (DFI_branch_target_load, decl);
3501 branch_target_load_optimize (insns, true);
3503 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3505 ggc_collect ();
3508 #ifdef INSN_SCHEDULING
3509 if (optimize > 0 && flag_schedule_insns_after_reload)
3510 rest_of_handle_sched2 (decl, insns);
3511 #endif
3513 #ifdef LEAF_REGISTERS
3514 current_function_uses_only_leaf_regs
3515 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3516 #endif
3518 #ifdef STACK_REGS
3519 rest_of_handle_stack_regs (decl, insns);
3520 #endif
3522 compute_alignments ();
3524 /* CFG is no longer maintained up-to-date. */
3525 free_bb_for_insn ();
3527 if (targetm.machine_dependent_reorg != 0)
3528 rest_of_handle_machine_reorg (decl, insns);
3530 purge_line_number_notes (insns);
3531 cleanup_barriers ();
3533 #ifdef DELAY_SLOTS
3534 if (optimize > 0 && flag_delayed_branch)
3535 rest_of_handle_delay_slots (decl, insns);
3536 #endif
3538 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3539 timevar_push (TV_SHORTEN_BRANCH);
3540 split_all_insns_noflow ();
3541 timevar_pop (TV_SHORTEN_BRANCH);
3542 #endif
3544 convert_to_eh_region_ranges ();
3546 /* Shorten branches. */
3547 timevar_push (TV_SHORTEN_BRANCH);
3548 shorten_branches (get_insns ());
3549 timevar_pop (TV_SHORTEN_BRANCH);
3551 set_nothrow_function_flags ();
3552 if (current_function_nothrow)
3553 /* Now we know that this can't throw; set the flag for the benefit
3554 of other functions later in this translation unit. */
3555 TREE_NOTHROW (current_function_decl) = 1;
3557 rest_of_handle_final (decl, insns);
3559 /* Write DBX symbols if requested. */
3561 /* Note that for those inline functions where we don't initially
3562 know for certain that we will be generating an out-of-line copy,
3563 the first invocation of this routine (rest_of_compilation) will
3564 skip over this code by doing a `goto exit_rest_of_compilation;'.
3565 Later on, wrapup_global_declarations will (indirectly) call
3566 rest_of_compilation again for those inline functions that need
3567 to have out-of-line copies generated. During that call, we
3568 *will* be routed past here. */
3570 timevar_push (TV_SYMOUT);
3571 (*debug_hooks->function_decl) (decl);
3572 timevar_pop (TV_SYMOUT);
3574 exit_rest_of_compilation:
3576 coverage_end_function ();
3578 /* In case the function was not output,
3579 don't leave any temporary anonymous types
3580 queued up for sdb output. */
3581 #ifdef SDB_DEBUGGING_INFO
3582 if (write_symbols == SDB_DEBUG)
3583 sdbout_types (NULL_TREE);
3584 #endif
3586 reload_completed = 0;
3587 epilogue_completed = 0;
3588 flow2_completed = 0;
3589 no_new_pseudos = 0;
3591 timevar_push (TV_FINAL);
3593 /* Clear out the insn_length contents now that they are no
3594 longer valid. */
3595 init_insn_lengths ();
3597 /* Show no temporary slots allocated. */
3598 init_temp_slots ();
3600 free_basic_block_vars (0);
3601 free_bb_for_insn ();
3603 timevar_pop (TV_FINAL);
3605 if ((*targetm.binds_local_p) (current_function_decl))
3607 int pref = cfun->preferred_stack_boundary;
3608 if (cfun->recursive_call_emit
3609 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3610 pref = cfun->stack_alignment_needed;
3611 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3612 = pref;
3615 /* Make sure volatile mem refs aren't considered valid operands for
3616 arithmetic insns. We must call this here if this is a nested inline
3617 function, since the above code leaves us in the init_recog state
3618 (from final.c), and the function context push/pop code does not
3619 save/restore volatile_ok.
3621 ??? Maybe it isn't necessary for expand_start_function to call this
3622 anymore if we do it here? */
3624 init_recog_no_volatile ();
3626 /* We're done with this function. Free up memory if we can. */
3627 free_after_parsing (cfun);
3628 if (! DECL_DEFER_OUTPUT (decl))
3630 free_after_compilation (cfun);
3631 DECL_SAVED_INSNS (decl) = 0;
3633 cfun = 0;
3635 ggc_collect ();
3637 timevar_pop (TV_REST_OF_COMPILATION);
3640 /* Display help for target options. */
3641 void
3642 display_target_options (void)
3644 int undoc, i;
3645 static bool displayed = false;
3647 /* Avoid double printing for --help --target-help. */
3648 if (displayed)
3649 return;
3651 displayed = true;
3653 if (ARRAY_SIZE (target_switches) > 1
3654 #ifdef TARGET_OPTIONS
3655 || ARRAY_SIZE (target_options) > 1
3656 #endif
3659 int doc = 0;
3661 undoc = 0;
3663 printf (_("\nTarget specific options:\n"));
3665 for (i = ARRAY_SIZE (target_switches); i--;)
3667 const char *option = target_switches[i].name;
3668 const char *description = target_switches[i].description;
3670 if (option == NULL || *option == 0)
3671 continue;
3672 else if (description == NULL)
3674 undoc = 1;
3676 if (extra_warnings)
3677 printf (_(" -m%-23s [undocumented]\n"), option);
3679 else if (*description != 0)
3680 doc += printf (" -m%-23s %s\n", option, _(description));
3683 #ifdef TARGET_OPTIONS
3684 for (i = ARRAY_SIZE (target_options); i--;)
3686 const char *option = target_options[i].prefix;
3687 const char *description = target_options[i].description;
3689 if (option == NULL || *option == 0)
3690 continue;
3691 else if (description == NULL)
3693 undoc = 1;
3695 if (extra_warnings)
3696 printf (_(" -m%-23s [undocumented]\n"), option);
3698 else if (*description != 0)
3699 doc += printf (" -m%-23s %s\n", option, _(description));
3701 #endif
3702 if (undoc)
3704 if (doc)
3705 printf (_("\nThere are undocumented target specific options as well.\n"));
3706 else
3707 printf (_(" They exist, but they are not documented.\n"));
3712 /* Parse a -d... command line switch. */
3714 void
3715 decode_d_option (const char *arg)
3717 int i, c, matched;
3719 while (*arg)
3720 switch (c = *arg++)
3722 case 'a':
3723 for (i = 0; i < (int) DFI_MAX; ++i)
3724 dump_file[i].enabled = 1;
3725 break;
3726 case 'A':
3727 flag_debug_asm = 1;
3728 break;
3729 case 'p':
3730 flag_print_asm_name = 1;
3731 break;
3732 case 'P':
3733 flag_dump_rtl_in_asm = 1;
3734 flag_print_asm_name = 1;
3735 break;
3736 case 'v':
3737 graph_dump_format = vcg;
3738 break;
3739 case 'x':
3740 rtl_dump_and_exit = 1;
3741 break;
3742 case 'y':
3743 set_yydebug = 1;
3744 break;
3745 case 'D': /* These are handled by the preprocessor. */
3746 case 'I':
3747 break;
3748 case 'H':
3749 setup_core_dumping();
3750 break;
3752 default:
3753 matched = 0;
3754 for (i = 0; i < (int) DFI_MAX; ++i)
3755 if (c == dump_file[i].debug_switch)
3757 dump_file[i].enabled = 1;
3758 matched = 1;
3761 if (! matched)
3762 warning ("unrecognized gcc debugging option: %c", c);
3763 break;
3767 /* Indexed by enum debug_info_type. */
3768 const char *const debug_type_names[] =
3770 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3773 /* Decode -m switches. */
3774 /* Decode the switch -mNAME. */
3776 void
3777 set_target_switch (const char *name)
3779 size_t j;
3780 int valid_target_option = 0;
3782 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3783 if (!strcmp (target_switches[j].name, name))
3785 if (target_switches[j].value < 0)
3786 target_flags &= ~-target_switches[j].value;
3787 else
3788 target_flags |= target_switches[j].value;
3789 if (name[0] != 0)
3791 if (target_switches[j].value < 0)
3792 target_flags_explicit |= -target_switches[j].value;
3793 else
3794 target_flags_explicit |= target_switches[j].value;
3796 valid_target_option = 1;
3799 #ifdef TARGET_OPTIONS
3800 if (!valid_target_option)
3801 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3803 int len = strlen (target_options[j].prefix);
3804 if (target_options[j].value)
3806 if (!strcmp (target_options[j].prefix, name))
3808 *target_options[j].variable = target_options[j].value;
3809 valid_target_option = 1;
3812 else
3814 if (!strncmp (target_options[j].prefix, name, len))
3816 *target_options[j].variable = name + len;
3817 valid_target_option = 1;
3821 #endif
3823 if (!valid_target_option)
3824 error ("invalid option `%s'", name);
3827 /* Print version information to FILE.
3828 Each line begins with INDENT (for the case where FILE is the
3829 assembler output file). */
3831 void
3832 print_version (FILE *file, const char *indent)
3834 #ifndef __VERSION__
3835 #define __VERSION__ "[?]"
3836 #endif
3837 fnotice (file,
3838 #ifdef __GNUC__
3839 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3840 #else
3841 "%s%s%s version %s (%s) compiled by CC.\n"
3842 #endif
3843 , indent, *indent != 0 ? " " : "",
3844 lang_hooks.name, version_string, TARGET_NAME,
3845 indent, __VERSION__);
3846 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3847 indent, *indent != 0 ? " " : "",
3848 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3851 /* Print an option value and return the adjusted position in the line.
3852 ??? We don't handle error returns from fprintf (disk full); presumably
3853 other code will catch a disk full though. */
3855 static int
3856 print_single_switch (FILE *file, int pos, int max,
3857 const char *indent, const char *sep, const char *term,
3858 const char *type, const char *name)
3860 /* The ultrix fprintf returns 0 on success, so compute the result we want
3861 here since we need it for the following test. */
3862 int len = strlen (sep) + strlen (type) + strlen (name);
3864 if (pos != 0
3865 && pos + len > max)
3867 fprintf (file, "%s", term);
3868 pos = 0;
3870 if (pos == 0)
3872 fprintf (file, "%s", indent);
3873 pos = strlen (indent);
3875 fprintf (file, "%s%s%s", sep, type, name);
3876 pos += len;
3877 return pos;
3880 /* Print active target switches to FILE.
3881 POS is the current cursor position and MAX is the size of a "line".
3882 Each line begins with INDENT and ends with TERM.
3883 Each switch is separated from the next by SEP. */
3885 static void
3886 print_switch_values (FILE *file, int pos, int max,
3887 const char *indent, const char *sep, const char *term)
3889 size_t j;
3890 const char **p;
3892 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3893 that it can be printed below. This helps reproducibility. */
3894 randomize ();
3896 /* Print the options as passed. */
3897 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3898 _("options passed: "), "");
3900 for (p = &save_argv[1]; *p != NULL; p++)
3901 if (**p == '-')
3903 /* Ignore these. */
3904 if (strcmp (*p, "-o") == 0)
3906 if (p[1] != NULL)
3907 p++;
3908 continue;
3910 if (strcmp (*p, "-quiet") == 0)
3911 continue;
3912 if (strcmp (*p, "-version") == 0)
3913 continue;
3914 if ((*p)[1] == 'd')
3915 continue;
3917 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
3919 if (pos > 0)
3920 fprintf (file, "%s", term);
3922 /* Print the -f and -m options that have been enabled.
3923 We don't handle language specific options but printing argv
3924 should suffice. */
3926 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
3927 _("options enabled: "), "");
3929 for (j = 0; j < ARRAY_SIZE (f_options); j++)
3930 if (*f_options[j].variable == f_options[j].on_value)
3931 pos = print_single_switch (file, pos, max, indent, sep, term,
3932 "-f", f_options[j].string);
3934 /* Print target specific options. */
3936 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3937 if (target_switches[j].name[0] != '\0'
3938 && target_switches[j].value > 0
3939 && ((target_switches[j].value & target_flags)
3940 == target_switches[j].value))
3942 pos = print_single_switch (file, pos, max, indent, sep, term,
3943 "-m", target_switches[j].name);
3946 #ifdef TARGET_OPTIONS
3947 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3948 if (*target_options[j].variable != NULL)
3950 char prefix[256];
3951 sprintf (prefix, "-m%s", target_options[j].prefix);
3952 pos = print_single_switch (file, pos, max, indent, sep, term,
3953 prefix, *target_options[j].variable);
3955 #endif
3957 fprintf (file, "%s", term);
3960 /* Open assembly code output file. Do this even if -fsyntax-only is
3961 on, because then the driver will have provided the name of a
3962 temporary file or bit bucket for us. NAME is the file specified on
3963 the command line, possibly NULL. */
3964 static void
3965 init_asm_output (const char *name)
3967 if (name == NULL && asm_file_name == 0)
3968 asm_out_file = stdout;
3969 else
3971 if (asm_file_name == 0)
3973 int len = strlen (dump_base_name);
3974 char *dumpname = xmalloc (len + 6);
3975 memcpy (dumpname, dump_base_name, len + 1);
3976 strip_off_ending (dumpname, len);
3977 strcat (dumpname, ".s");
3978 asm_file_name = dumpname;
3980 if (!strcmp (asm_file_name, "-"))
3981 asm_out_file = stdout;
3982 else
3983 asm_out_file = fopen (asm_file_name, "w+");
3984 if (asm_out_file == 0)
3985 fatal_error ("can't open %s for writing: %m", asm_file_name);
3988 #ifdef IO_BUFFER_SIZE
3989 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
3990 _IOFBF, IO_BUFFER_SIZE);
3991 #endif
3993 if (!flag_syntax_only)
3995 targetm.asm_out.file_start ();
3997 #ifdef ASM_COMMENT_START
3998 if (flag_verbose_asm)
4000 /* Print the list of options in effect. */
4001 print_version (asm_out_file, ASM_COMMENT_START);
4002 print_switch_values (asm_out_file, 0, MAX_LINE,
4003 ASM_COMMENT_START, " ", "\n");
4004 /* Add a blank line here so it appears in assembler output but not
4005 screen output. */
4006 fprintf (asm_out_file, "\n");
4008 #endif
4012 /* Default version of get_pch_validity.
4013 By default, every flag difference is fatal; that will be mostly right for
4014 most targets, but completely right for very few. */
4016 void *
4017 default_get_pch_validity (size_t *len)
4019 #ifdef TARGET_OPTIONS
4020 size_t i;
4021 #endif
4022 char *result, *r;
4024 *len = sizeof (target_flags) + 2;
4025 #ifdef TARGET_OPTIONS
4026 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4028 *len += 1;
4029 if (*target_options[i].variable)
4030 *len += strlen (*target_options[i].variable);
4032 #endif
4034 result = r = xmalloc (*len);
4035 r[0] = flag_pic;
4036 r[1] = flag_pie;
4037 r += 2;
4038 memcpy (r, &target_flags, sizeof (target_flags));
4039 r += sizeof (target_flags);
4041 #ifdef TARGET_OPTIONS
4042 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4044 const char *str = *target_options[i].variable;
4045 size_t l;
4046 if (! str)
4047 str = "";
4048 l = strlen (str) + 1;
4049 memcpy (r, str, l);
4050 r += l;
4052 #endif
4054 return result;
4057 /* Default version of pch_valid_p. */
4059 const char *
4060 default_pch_valid_p (const void *data_p, size_t len)
4062 const char *data = (const char *)data_p;
4063 const char *flag_that_differs = NULL;
4064 size_t i;
4066 /* -fpic and -fpie also usually make a PCH invalid. */
4067 if (data[0] != flag_pic)
4068 return _("created and used with different settings of -fpic");
4069 if (data[1] != flag_pie)
4070 return _("created and used with different settings of -fpie");
4071 data += 2;
4073 /* Check target_flags. */
4074 if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
4076 for (i = 0; i < ARRAY_SIZE (target_switches); i++)
4078 int bits;
4079 int tf;
4081 memcpy (&tf, data, sizeof (target_flags));
4083 bits = target_switches[i].value;
4084 if (bits < 0)
4085 bits = -bits;
4086 if ((target_flags & bits) != (tf & bits))
4088 flag_that_differs = target_switches[i].name;
4089 goto make_message;
4092 abort ();
4094 data += sizeof (target_flags);
4095 len -= sizeof (target_flags);
4097 /* Check string options. */
4098 #ifdef TARGET_OPTIONS
4099 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4101 const char *str = *target_options[i].variable;
4102 size_t l;
4103 if (! str)
4104 str = "";
4105 l = strlen (str) + 1;
4106 if (len < l || memcmp (data, str, l) != 0)
4108 flag_that_differs = target_options[i].prefix;
4109 goto make_message;
4111 data += l;
4112 len -= l;
4114 #endif
4116 return NULL;
4118 make_message:
4120 char *r;
4121 asprintf (&r, _("created and used with differing settings of `-m%s'"),
4122 flag_that_differs);
4123 if (r == NULL)
4124 return _("out of memory");
4125 return r;
4129 /* Default tree printer. Handles declarations only. */
4130 static bool
4131 default_tree_printer (pretty_printer * pp, text_info *text)
4133 switch (*text->format_spec)
4135 case 'D':
4136 case 'F':
4137 case 'T':
4139 tree t = va_arg (*text->args_ptr, tree);
4140 const char *n = DECL_NAME (t)
4141 ? (*lang_hooks.decl_printable_name) (t, 2)
4142 : "<anonymous>";
4143 pp_string (pp, n);
4145 return true;
4147 default:
4148 return false;
4152 /* Initialization of the front end environment, before command line
4153 options are parsed. Signal handlers, internationalization etc.
4154 ARGV0 is main's argv[0]. */
4155 static void
4156 general_init (const char *argv0)
4158 const char *p;
4160 p = argv0 + strlen (argv0);
4161 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4162 --p;
4163 progname = p;
4165 xmalloc_set_program_name (progname);
4167 hex_init ();
4169 gcc_init_libintl ();
4171 /* Initialize the diagnostics reporting machinery, so option parsing
4172 can give warnings and errors. */
4173 diagnostic_initialize (global_dc);
4174 /* Set a default printer. Language specific initializations will
4175 override it later. */
4176 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4178 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4179 #ifdef SIGSEGV
4180 signal (SIGSEGV, crash_signal);
4181 #endif
4182 #ifdef SIGILL
4183 signal (SIGILL, crash_signal);
4184 #endif
4185 #ifdef SIGBUS
4186 signal (SIGBUS, crash_signal);
4187 #endif
4188 #ifdef SIGABRT
4189 signal (SIGABRT, crash_signal);
4190 #endif
4191 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4192 signal (SIGIOT, crash_signal);
4193 #endif
4194 #ifdef SIGFPE
4195 signal (SIGFPE, crash_signal);
4196 #endif
4198 /* Other host-specific signal setup. */
4199 (*host_hooks.extra_signals)();
4201 /* Initialize the garbage-collector, string pools and tree type hash
4202 table. */
4203 init_ggc ();
4204 init_stringpool ();
4205 init_ttree ();
4207 /* Initialize register usage now so switches may override. */
4208 init_reg_sets ();
4210 /* Register the language-independent parameters. */
4211 add_params (lang_independent_params, LAST_PARAM);
4213 /* This must be done after add_params but before argument processing. */
4214 init_ggc_heuristics();
4217 /* Process the options that have been parsed. */
4218 static void
4219 process_options (void)
4221 /* Allow the front end to perform consistency checks and do further
4222 initialization based on the command line options. This hook also
4223 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4224 so we can correctly initialize debug output. */
4225 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4226 input_filename = main_input_filename;
4228 #ifdef OVERRIDE_OPTIONS
4229 /* Some machines may reject certain combinations of options. */
4230 OVERRIDE_OPTIONS;
4231 #endif
4233 /* Set aux_base_name if not already set. */
4234 if (aux_base_name)
4236 else if (main_input_filename)
4238 char *name = xstrdup (lbasename (main_input_filename));
4240 strip_off_ending (name, strlen (name));
4241 aux_base_name = name;
4243 else
4244 aux_base_name = "gccaux";
4246 /* Set up the align_*_log variables, defaulting them to 1 if they
4247 were still unset. */
4248 if (align_loops <= 0) align_loops = 1;
4249 if (align_loops_max_skip > align_loops || !align_loops)
4250 align_loops_max_skip = align_loops - 1;
4251 align_loops_log = floor_log2 (align_loops * 2 - 1);
4252 if (align_jumps <= 0) align_jumps = 1;
4253 if (align_jumps_max_skip > align_jumps || !align_jumps)
4254 align_jumps_max_skip = align_jumps - 1;
4255 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4256 if (align_labels <= 0) align_labels = 1;
4257 align_labels_log = floor_log2 (align_labels * 2 - 1);
4258 if (align_labels_max_skip > align_labels || !align_labels)
4259 align_labels_max_skip = align_labels - 1;
4260 if (align_functions <= 0) align_functions = 1;
4261 align_functions_log = floor_log2 (align_functions * 2 - 1);
4263 /* Unrolling all loops implies that standard loop unrolling must also
4264 be done. */
4265 if (flag_unroll_all_loops)
4266 flag_unroll_loops = 1;
4268 if (flag_unroll_loops)
4270 flag_old_unroll_loops = 0;
4271 flag_old_unroll_all_loops = 0;
4274 if (flag_old_unroll_all_loops)
4275 flag_old_unroll_loops = 1;
4277 /* Old loop unrolling requires that strength_reduction be on also. Silently
4278 turn on strength reduction here if it isn't already on. Also, the loop
4279 unrolling code assumes that cse will be run after loop, so that must
4280 be turned on also. */
4281 if (flag_old_unroll_loops)
4283 flag_strength_reduce = 1;
4284 flag_rerun_cse_after_loop = 1;
4286 if (flag_unroll_loops || flag_peel_loops)
4287 flag_rerun_cse_after_loop = 1;
4289 if (flag_non_call_exceptions)
4290 flag_asynchronous_unwind_tables = 1;
4291 if (flag_asynchronous_unwind_tables)
4292 flag_unwind_tables = 1;
4294 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4295 interface. */
4296 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4297 flag_unit_at_a_time = 0;
4299 if (flag_value_profile_transformations)
4300 flag_profile_values = 1;
4302 /* Warn about options that are not supported on this machine. */
4303 #ifndef INSN_SCHEDULING
4304 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4305 warning ("instruction scheduling not supported on this target machine");
4306 #endif
4307 #ifndef DELAY_SLOTS
4308 if (flag_delayed_branch)
4309 warning ("this target machine does not have delayed branches");
4310 #endif
4312 user_label_prefix = USER_LABEL_PREFIX;
4313 if (flag_leading_underscore != -1)
4315 /* If the default prefix is more complicated than "" or "_",
4316 issue a warning and ignore this option. */
4317 if (user_label_prefix[0] == 0 ||
4318 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4320 user_label_prefix = flag_leading_underscore ? "_" : "";
4322 else
4323 warning ("-f%sleading-underscore not supported on this target machine",
4324 flag_leading_underscore ? "" : "no-");
4327 /* If we are in verbose mode, write out the version and maybe all the
4328 option flags in use. */
4329 if (version_flag)
4331 print_version (stderr, "");
4332 if (! quiet_flag)
4333 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4336 if (flag_syntax_only)
4338 write_symbols = NO_DEBUG;
4339 profile_flag = 0;
4342 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4343 level is 0. */
4344 if (debug_info_level == DINFO_LEVEL_NONE)
4345 write_symbols = NO_DEBUG;
4347 /* Now we know write_symbols, set up the debug hooks based on it.
4348 By default we do nothing for debug output. */
4349 if (write_symbols == NO_DEBUG)
4350 debug_hooks = &do_nothing_debug_hooks;
4351 #if defined(DBX_DEBUGGING_INFO)
4352 else if (write_symbols == DBX_DEBUG)
4353 debug_hooks = &dbx_debug_hooks;
4354 #endif
4355 #if defined(XCOFF_DEBUGGING_INFO)
4356 else if (write_symbols == XCOFF_DEBUG)
4357 debug_hooks = &xcoff_debug_hooks;
4358 #endif
4359 #ifdef SDB_DEBUGGING_INFO
4360 else if (write_symbols == SDB_DEBUG)
4361 debug_hooks = &sdb_debug_hooks;
4362 #endif
4363 #ifdef DWARF2_DEBUGGING_INFO
4364 else if (write_symbols == DWARF2_DEBUG)
4365 debug_hooks = &dwarf2_debug_hooks;
4366 #endif
4367 #ifdef VMS_DEBUGGING_INFO
4368 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4369 debug_hooks = &vmsdbg_debug_hooks;
4370 #endif
4371 else
4372 error ("target system does not support the \"%s\" debug format",
4373 debug_type_names[write_symbols]);
4375 /* If auxiliary info generation is desired, open the output file.
4376 This goes in the same directory as the source file--unlike
4377 all the other output files. */
4378 if (flag_gen_aux_info)
4380 aux_info_file = fopen (aux_info_file_name, "w");
4381 if (aux_info_file == 0)
4382 fatal_error ("can't open %s: %m", aux_info_file_name);
4385 if (! targetm.have_named_sections)
4387 if (flag_function_sections)
4389 warning ("-ffunction-sections not supported for this target");
4390 flag_function_sections = 0;
4392 if (flag_data_sections)
4394 warning ("-fdata-sections not supported for this target");
4395 flag_data_sections = 0;
4399 if (flag_function_sections && profile_flag)
4401 warning ("-ffunction-sections disabled; it makes profiling impossible");
4402 flag_function_sections = 0;
4405 #ifndef HAVE_prefetch
4406 if (flag_prefetch_loop_arrays)
4408 warning ("-fprefetch-loop-arrays not supported for this target");
4409 flag_prefetch_loop_arrays = 0;
4411 #else
4412 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4414 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4415 flag_prefetch_loop_arrays = 0;
4417 #endif
4419 /* This combination of options isn't handled for i386 targets and doesn't
4420 make much sense anyway, so don't allow it. */
4421 if (flag_prefetch_loop_arrays && optimize_size)
4423 warning ("-fprefetch-loop-arrays is not supported with -Os");
4424 flag_prefetch_loop_arrays = 0;
4427 #ifndef OBJECT_FORMAT_ELF
4428 if (flag_function_sections && write_symbols != NO_DEBUG)
4429 warning ("-ffunction-sections may affect debugging on some targets");
4430 #endif
4432 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4433 if (flag_signaling_nans)
4434 flag_trapping_math = 1;
4437 /* Initialize the compiler back end. */
4438 static void
4439 backend_init (void)
4441 init_adjust_machine_modes ();
4443 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4444 || debug_info_level == DINFO_LEVEL_VERBOSE
4445 #ifdef VMS_DEBUGGING_INFO
4446 /* Enable line number info for traceback. */
4447 || debug_info_level > DINFO_LEVEL_NONE
4448 #endif
4449 || flag_test_coverage
4450 || warn_notreached);
4452 init_regs ();
4453 init_fake_stack_mems ();
4454 init_alias_once ();
4455 init_loop ();
4456 init_reload ();
4457 init_function_once ();
4458 init_varasm_once ();
4460 /* The following initialization functions need to generate rtl, so
4461 provide a dummy function context for them. */
4462 init_dummy_function_start ();
4463 init_expmed ();
4464 if (flag_caller_saves)
4465 init_caller_save ();
4466 expand_dummy_function_end ();
4469 /* Language-dependent initialization. Returns nonzero on success. */
4470 static int
4471 lang_dependent_init (const char *name)
4473 if (dump_base_name == 0)
4474 dump_base_name = name ? name : "gccdump";
4476 /* Other front-end initialization. */
4477 if ((*lang_hooks.init) () == 0)
4478 return 0;
4480 init_asm_output (name);
4482 /* These create various _DECL nodes, so need to be called after the
4483 front end is initialized. */
4484 init_eh ();
4485 init_optabs ();
4487 /* The following initialization functions need to generate rtl, so
4488 provide a dummy function context for them. */
4489 init_dummy_function_start ();
4490 init_expr_once ();
4491 expand_dummy_function_end ();
4493 /* If dbx symbol table desired, initialize writing it and output the
4494 predefined types. */
4495 timevar_push (TV_SYMOUT);
4497 #ifdef DWARF2_UNWIND_INFO
4498 if (dwarf2out_do_frame ())
4499 dwarf2out_frame_init ();
4500 #endif
4502 /* Now we have the correct original filename, we can initialize
4503 debug output. */
4504 (*debug_hooks->init) (name);
4506 timevar_pop (TV_SYMOUT);
4508 return 1;
4511 /* Clean up: close opened files, etc. */
4513 static void
4514 finalize (void)
4516 /* Close the dump files. */
4517 if (flag_gen_aux_info)
4519 fclose (aux_info_file);
4520 if (errorcount)
4521 unlink (aux_info_file_name);
4524 /* Close non-debugging input and output files. Take special care to note
4525 whether fclose returns an error, since the pages might still be on the
4526 buffer chain while the file is open. */
4528 if (asm_out_file)
4530 if (ferror (asm_out_file) != 0)
4531 fatal_error ("error writing to %s: %m", asm_file_name);
4532 if (fclose (asm_out_file) != 0)
4533 fatal_error ("error closing %s: %m", asm_file_name);
4536 /* Do whatever is necessary to finish printing the graphs. */
4537 if (graph_dump_format != no_graph)
4539 int i;
4541 for (i = 0; i < (int) DFI_MAX; ++i)
4542 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4544 char seq[16];
4545 char *suffix;
4547 sprintf (seq, DUMPFILE_FORMAT, i);
4548 suffix = concat (seq, dump_file[i].extension, NULL);
4549 finish_graph_dump_file (dump_base_name, suffix);
4550 free (suffix);
4554 if (mem_report)
4556 ggc_print_statistics ();
4557 stringpool_statistics ();
4558 dump_tree_statistics ();
4559 dump_rtx_statistics ();
4562 /* Free up memory for the benefit of leak detectors. */
4563 free_reg_info ();
4565 /* Language-specific end of compilation actions. */
4566 (*lang_hooks.finish) ();
4569 /* Initialize the compiler, and compile the input file. */
4570 static void
4571 do_compile (void)
4573 /* Initialize timing first. The C front ends read the main file in
4574 the post_options hook, and C++ does file timings. */
4575 if (time_report || !quiet_flag || flag_detailed_statistics)
4576 timevar_init ();
4577 timevar_start (TV_TOTAL);
4579 process_options ();
4581 /* Don't do any more if an error has already occurred. */
4582 if (!errorcount)
4584 /* Set up the back-end if requested. */
4585 if (!no_backend)
4586 backend_init ();
4588 /* Language-dependent initialization. Returns true on success. */
4589 if (lang_dependent_init (main_input_filename))
4591 if (flag_unit_at_a_time)
4593 open_dump_file (DFI_cgraph, NULL);
4594 cgraph_dump_file = rtl_dump_file;
4595 rtl_dump_file = NULL;
4598 compile_file ();
4600 if (flag_unit_at_a_time)
4602 rtl_dump_file = cgraph_dump_file;
4603 cgraph_dump_file = NULL;
4604 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4608 finalize ();
4611 /* Stop timing and print the times. */
4612 timevar_stop (TV_TOTAL);
4613 timevar_print (stderr);
4616 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4617 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4618 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4620 It is not safe to call this function more than once. */
4623 toplev_main (unsigned int argc, const char **argv)
4625 save_argv = argv;
4627 /* Initialization of GCC's environment, and diagnostics. */
4628 general_init (argv[0]);
4630 /* Parse the options and do minimal processing; basically just
4631 enough to default flags appropriately. */
4632 decode_options (argc, argv);
4634 randomize ();
4636 /* Exit early if we can (e.g. -help). */
4637 if (!exit_after_options)
4638 do_compile ();
4640 if (errorcount || sorrycount)
4641 return (FATAL_EXIT_CODE);
4643 return (SUCCESS_EXIT_CODE);