PR gcc/1532
[official-gcc.git] / gcc / toplev.c
blob4d16201c177b78841107f0ec1c1976267925b4fb
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 #ifndef HAVE_conditional_execution
100 #define HAVE_conditional_execution 0
101 #endif
103 /* Carry information from ASM_DECLARE_OBJECT_NAME
104 to ASM_FINISH_DECLARE_OBJECT. */
106 extern int size_directive_output;
107 extern tree last_assemble_variable_decl;
109 extern void reg_alloc (void);
111 static void general_init (const char *);
112 static void do_compile (void);
113 static void process_options (void);
114 static void backend_init (void);
115 static int lang_dependent_init (const char *);
116 static void init_asm_output (const char *);
117 static void finalize (void);
119 static void crash_signal (int) ATTRIBUTE_NORETURN;
120 static void setup_core_dumping (void);
121 static void compile_file (void);
123 static int print_single_switch (FILE *, int, int, const char *,
124 const char *, const char *,
125 const char *, const char *);
126 static void print_switch_values (FILE *, int, int, const char *,
127 const char *, const char *);
129 /* Rest of compilation helper functions. */
130 static bool rest_of_handle_inlining (tree);
131 static void rest_of_handle_cse (tree, rtx);
132 static void rest_of_handle_cse2 (tree, rtx);
133 static void rest_of_handle_gcse (tree, rtx);
134 static void rest_of_handle_life (tree, rtx);
135 static void rest_of_handle_loop_optimize (tree, rtx);
136 static void rest_of_handle_loop2 (tree, rtx);
137 static void rest_of_handle_jump_bypass (tree, rtx);
138 static void rest_of_handle_sibling_calls (rtx);
139 static void rest_of_handle_null_pointer (tree, rtx);
140 static void rest_of_handle_addressof (tree, rtx);
141 static void rest_of_handle_cfg (tree, rtx);
142 static void rest_of_handle_branch_prob (tree, rtx);
143 static void rest_of_handle_value_profile_transformations (tree, rtx);
144 static void rest_of_handle_if_conversion (tree, rtx);
145 static void rest_of_handle_if_after_combine (tree, rtx);
146 static void rest_of_handle_tracer (tree, rtx);
147 static void rest_of_handle_combine (tree, rtx);
148 static void rest_of_handle_regmove (tree, rtx);
149 #ifdef INSN_SCHEDULING
150 static void rest_of_handle_sched (tree, rtx);
151 static void rest_of_handle_sched2 (tree, rtx);
152 #endif
153 static bool rest_of_handle_new_regalloc (tree, rtx);
154 static bool rest_of_handle_old_regalloc (tree, rtx);
155 static void rest_of_handle_regrename (tree, rtx);
156 static void rest_of_handle_reorder_blocks (tree, rtx);
157 #ifdef STACK_REGS
158 static void rest_of_handle_stack_regs (tree, rtx);
159 #endif
160 static void rest_of_handle_machine_reorg (tree, rtx);
161 #ifdef DELAY_SLOTS
162 static void rest_of_handle_delay_slots (tree, rtx);
163 #endif
164 static void rest_of_handle_final (tree, rtx);
166 /* Nonzero to dump debug info whilst parsing (-dy option). */
167 static int set_yydebug;
169 /* True if we don't need a backend (e.g. preprocessing only). */
170 static bool no_backend;
172 /* Length of line when printing switch values. */
173 #define MAX_LINE 75
175 /* Name of program invoked, sans directories. */
177 const char *progname;
179 /* Copy of argument vector to toplev_main. */
180 static const char **save_argv;
182 /* Name of top-level original source file (what was input to cpp).
183 This comes from the #-command at the beginning of the actual input.
184 If there isn't any there, then this is the cc1 input file name. */
186 const char *main_input_filename;
188 /* Current position in real source file. */
190 location_t input_location;
192 struct line_maps line_table;
194 /* Nonzero if it is unsafe to create any new pseudo registers. */
195 int no_new_pseudos;
197 /* Stack of currently pending input files. */
199 struct file_stack *input_file_stack;
201 /* Incremented on each change to input_file_stack. */
202 int input_file_stack_tick;
204 /* Name to use as base of names for dump output files. */
206 const char *dump_base_name;
208 /* Name to use as a base for auxiliary output files. */
210 const char *aux_base_name;
212 /* Format to use to print dumpfile index value */
213 #ifndef DUMPFILE_FORMAT
214 #define DUMPFILE_FORMAT ".%02d."
215 #endif
217 /* Bit flags that specify the machine subtype we are compiling for.
218 Bits are tested using macros TARGET_... defined in the tm.h file
219 and set by `-m...' switches. Must be defined in rtlanal.c. */
221 extern int target_flags;
223 /* A mask of target_flags that includes bit X if X was set or cleared
224 on the command line. */
226 int target_flags_explicit;
228 /* Debug hooks - dependent upon command line options. */
230 const struct gcc_debug_hooks *debug_hooks;
232 /* Describes a dump file. */
234 struct dump_file_info
236 /* The unique extension to apply, e.g. ".jump". */
237 const char *const extension;
239 /* The -d<c> character that enables this dump file. */
240 char const debug_switch;
242 /* True if there is a corresponding graph dump file. */
243 char const graph_dump_p;
245 /* True if the user selected this dump. */
246 char enabled;
248 /* True if the files have been initialized (ie truncated). */
249 char initialized;
252 /* Enumerate the extant dump files. */
254 enum dump_file_index
256 DFI_cgraph,
257 DFI_rtl,
258 DFI_sibling,
259 DFI_eh,
260 DFI_jump,
261 DFI_null,
262 DFI_cse,
263 DFI_addressof,
264 DFI_gcse,
265 DFI_loop,
266 DFI_bypass,
267 DFI_cfg,
268 DFI_bp,
269 DFI_vpt,
270 DFI_ce1,
271 DFI_tracer,
272 DFI_loop2,
273 DFI_web,
274 DFI_cse2,
275 DFI_life,
276 DFI_combine,
277 DFI_ce2,
278 DFI_regmove,
279 DFI_sched,
280 DFI_lreg,
281 DFI_greg,
282 DFI_postreload,
283 DFI_flow2,
284 DFI_peephole2,
285 DFI_rnreg,
286 DFI_ce3,
287 DFI_bbro,
288 DFI_branch_target_load,
289 DFI_sched2,
290 DFI_stack,
291 DFI_mach,
292 DFI_dbr,
293 DFI_MAX
296 /* Describes all the dump files. Should be kept in order of the
297 pass and in sync with dump_file_index above.
299 Remaining -d letters:
301 " e m q "
302 " JK O Q WXY "
305 static struct dump_file_info dump_file[DFI_MAX] =
307 { "cgraph", 'U', 0, 0, 0 },
308 { "rtl", 'r', 0, 0, 0 },
309 { "sibling", 'i', 0, 0, 0 },
310 { "eh", 'h', 0, 0, 0 },
311 { "jump", 'j', 0, 0, 0 },
312 { "null", 'u', 0, 0, 0 },
313 { "cse", 's', 0, 0, 0 },
314 { "addressof", 'F', 0, 0, 0 },
315 { "gcse", 'G', 1, 0, 0 },
316 { "loop", 'L', 1, 0, 0 },
317 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
318 { "cfg", 'f', 1, 0, 0 },
319 { "bp", 'b', 1, 0, 0 },
320 { "vpt", 'V', 1, 0, 0 },
321 { "ce1", 'C', 1, 0, 0 },
322 { "tracer", 'T', 1, 0, 0 },
323 { "loop2", 'L', 1, 0, 0 },
324 { "web", 'Z', 0, 0, 0 },
325 { "cse2", 't', 1, 0, 0 },
326 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
327 { "combine", 'c', 1, 0, 0 },
328 { "ce2", 'C', 1, 0, 0 },
329 { "regmove", 'N', 1, 0, 0 },
330 { "sched", 'S', 1, 0, 0 },
331 { "lreg", 'l', 1, 0, 0 },
332 { "greg", 'g', 1, 0, 0 },
333 { "postreload", 'o', 1, 0, 0 },
334 { "flow2", 'w', 1, 0, 0 },
335 { "peephole2", 'z', 1, 0, 0 },
336 { "rnreg", 'n', 1, 0, 0 },
337 { "ce3", 'E', 1, 0, 0 },
338 { "bbro", 'B', 1, 0, 0 },
339 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
340 { "sched2", 'R', 1, 0, 0 },
341 { "stack", 'k', 1, 0, 0 },
342 { "mach", 'M', 1, 0, 0 },
343 { "dbr", 'd', 0, 0, 0 },
346 static int open_dump_file (enum dump_file_index, tree);
347 static void close_dump_file (enum dump_file_index,
348 void (*) (FILE *, rtx), rtx);
350 /* Other flags saying which kinds of debugging dump have been requested. */
352 int rtl_dump_and_exit;
353 int flag_print_asm_name;
354 enum graph_dump_types graph_dump_format;
356 /* Name for output file of assembly code, specified with -o. */
358 const char *asm_file_name;
360 /* Nonzero means do optimizations. -O.
361 Particular numeric values stand for particular amounts of optimization;
362 thus, -O2 stores 2 here. However, the optimizations beyond the basic
363 ones are not controlled directly by this variable. Instead, they are
364 controlled by individual `flag_...' variables that are defaulted
365 based on this variable. */
367 int optimize = 0;
369 /* Nonzero means optimize for size. -Os.
370 The only valid values are zero and nonzero. When optimize_size is
371 nonzero, optimize defaults to 2, but certain individual code
372 bloating optimizations are disabled. */
374 int optimize_size = 0;
376 /* The FUNCTION_DECL for the function currently being compiled,
377 or 0 if between functions. */
378 tree current_function_decl;
380 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
381 if none. */
382 tree current_function_func_begin_label;
384 /* Nonzero if doing dwarf2 duplicate elimination. */
386 int flag_eliminate_dwarf2_dups = 0;
388 /* Nonzero if doing unused type elimination. */
390 int flag_eliminate_unused_debug_types = 1;
392 /* Nonzero means emit debugging information only for symbols which are used. */
393 int flag_debug_only_used_symbols = 0;
395 /* Nonzero if generating code to do profiling. */
397 int profile_flag = 0;
399 /* Nonzero if generating code to profile program flow graph arcs. */
401 int profile_arc_flag = 0;
403 /* Nonzero if value histograms should be measured. */
405 int flag_profile_values = 0;
407 /* Nonzero if value histograms should be used to optimize code. */
408 int flag_value_profile_transformations = 0;
410 /* Nonzero if generating info for gcov to calculate line test coverage. */
412 int flag_test_coverage = 0;
414 /* Nonzero indicates that branch taken probabilities should be calculated. */
416 int flag_branch_probabilities = 0;
418 /* Nonzero if basic blocks should be reordered. */
420 int flag_reorder_blocks = 0;
422 /* Nonzero if functions should be reordered. */
424 int flag_reorder_functions = 0;
426 /* Nonzero if registers should be renamed. */
428 int flag_rename_registers = 0;
429 int flag_cprop_registers = 0;
431 /* Nonzero for -pedantic switch: warn about anything
432 that standard spec forbids. */
434 int pedantic = 0;
436 /* Temporarily suppress certain warnings.
437 This is set while reading code from a system header file. */
439 int in_system_header = 0;
441 /* Don't print functions as they are compiled. -quiet. */
443 int quiet_flag = 0;
445 /* Print times taken by the various passes. -ftime-report. */
447 int time_report = 0;
449 /* Print memory still in use at end of compilation (which may have little
450 to do with peak memory consumption). -fmem-report. */
452 int mem_report = 0;
454 /* Nonzero means to collect statistics which might be expensive
455 and to print them when we are done. */
456 int flag_detailed_statistics = 0;
458 /* A random sequence of characters, unless overridden by user. */
459 const char *flag_random_seed;
461 /* A local time stamp derived from the time of compilation. It will be
462 zero if the system cannot provide a time. It will be -1u, if the
463 user has specified a particular random seed. */
464 unsigned local_tick;
466 /* -f flags. */
468 /* Nonzero means `char' should be signed. */
470 int flag_signed_char;
472 /* Nonzero means give an enum type only as many bytes as it needs. */
474 int flag_short_enums;
476 /* Nonzero for -fcaller-saves: allocate values in regs that need to
477 be saved across function calls, if that produces overall better code.
478 Optional now, so people can test it. */
480 int flag_caller_saves = 0;
482 /* Nonzero if structures and unions should be returned in memory.
484 This should only be defined if compatibility with another compiler or
485 with an ABI is needed, because it results in slower code. */
487 #ifndef DEFAULT_PCC_STRUCT_RETURN
488 #define DEFAULT_PCC_STRUCT_RETURN 1
489 #endif
491 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
493 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
495 /* Nonzero for -fforce-mem: load memory value into a register
496 before arithmetic on it. This makes better cse but slower compilation. */
498 int flag_force_mem = 0;
500 /* Nonzero for -fforce-addr: load memory address into a register before
501 reference to memory. This makes better cse but slower compilation. */
503 int flag_force_addr = 0;
505 /* Nonzero for -fdefer-pop: don't pop args after each function call;
506 instead save them up to pop many calls' args with one insns. */
508 int flag_defer_pop = 0;
510 /* Nonzero for -ffloat-store: don't allocate floats and doubles
511 in extended-precision registers. */
513 int flag_float_store = 0;
515 /* Nonzero for -fcse-follow-jumps:
516 have cse follow jumps to do a more extensive job. */
518 int flag_cse_follow_jumps;
520 /* Nonzero for -fcse-skip-blocks:
521 have cse follow a branch around a block. */
522 int flag_cse_skip_blocks;
524 /* Nonzero for -fexpensive-optimizations:
525 perform miscellaneous relatively-expensive optimizations. */
526 int flag_expensive_optimizations;
528 /* Nonzero for -fthread-jumps:
529 have jump optimize output of loop. */
531 int flag_thread_jumps;
533 /* Nonzero enables strength-reduction in loop.c. */
535 int flag_strength_reduce = 0;
537 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
538 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
539 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
540 unrolled. */
542 int flag_old_unroll_loops;
544 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
545 This is generally not a win. */
547 int flag_old_unroll_all_loops;
549 /* Enables unrolling of simple loops in loop-unroll.c. */
550 int flag_unroll_loops;
552 /* Enables unrolling of all loops in loop-unroll.c. */
553 int flag_unroll_all_loops;
555 /* Nonzero enables loop peeling. */
556 int flag_peel_loops;
558 /* Nonzero enables loop unswitching. */
559 int flag_unswitch_loops;
561 /* Nonzero enables prefetch optimizations for arrays in loops. */
563 int flag_prefetch_loop_arrays;
565 /* Nonzero forces all invariant computations in loops to be moved
566 outside the loop. */
568 int flag_move_all_movables = 0;
570 /* Nonzero forces all general induction variables in loops to be
571 strength reduced. */
573 int flag_reduce_all_givs = 0;
575 /* Nonzero to perform full register move optimization passes. This is the
576 default for -O2. */
578 int flag_regmove = 0;
580 /* Nonzero for -fwritable-strings:
581 store string constants in data segment and don't uniquize them. */
583 int flag_writable_strings = 0;
585 /* Nonzero means don't put addresses of constant functions in registers.
586 Used for compiling the Unix kernel, where strange substitutions are
587 done on the assembly output. */
589 int flag_no_function_cse = 0;
591 /* Nonzero for -fomit-frame-pointer:
592 don't make a frame pointer in simple functions that don't require one. */
594 int flag_omit_frame_pointer = 0;
596 /* Nonzero means place each function into its own section on those platforms
597 which support arbitrary section names and unlimited numbers of sections. */
599 int flag_function_sections = 0;
601 /* ... and similar for data. */
603 int flag_data_sections = 0;
605 /* Nonzero to inhibit use of define_optimization peephole opts. */
607 int flag_no_peephole = 0;
609 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
611 int flag_optimize_sibling_calls = 0;
613 /* Nonzero means the front end generally wants `errno' maintained by math
614 operations, like built-in SQRT. */
616 int flag_errno_math = 1;
618 /* Nonzero means that unsafe floating-point math optimizations are allowed
619 for the sake of speed. IEEE compliance is not guaranteed, and operations
620 are allowed to assume that their arguments and results are "normal"
621 (e.g., nonnegative for SQRT). */
623 int flag_unsafe_math_optimizations = 0;
625 /* Nonzero means that no NaNs or +-Infs are expected. */
627 int flag_finite_math_only = 0;
629 /* Zero means that floating-point math operations cannot generate a
630 (user-visible) trap. This is the case, for example, in nonstop
631 IEEE 754 arithmetic. Trapping conditions include division by zero,
632 overflow, underflow, invalid and inexact, but does not include
633 operations on signaling NaNs (see below). */
635 int flag_trapping_math = 1;
637 /* Nonzero means disable transformations that assume default floating
638 point rounding behavior. */
640 int flag_rounding_math = 0;
642 /* Nonzero means disable transformations observable by signaling NaNs.
643 This option implies that any operation on an IEEE signaling NaN can
644 generate a (user-visible) trap. */
646 int flag_signaling_nans = 0;
648 /* 0 means straightforward implementation of complex divide acceptable.
649 1 means wide ranges of inputs must work for complex divide.
650 2 means C99-like requirements for complex divide (not yet implemented). */
652 int flag_complex_divide_method = 0;
654 /* Nonzero means just do syntax checking; don't output anything. */
656 int flag_syntax_only = 0;
658 /* Nonzero means performs web construction pass. */
660 int flag_web;
662 /* Nonzero means perform loop optimizer. */
664 int flag_loop_optimize;
666 /* Nonzero means perform crossjumping. */
668 int flag_crossjumping;
670 /* Nonzero means perform if conversion. */
672 int flag_if_conversion;
674 /* Nonzero means perform if conversion after reload. */
676 int flag_if_conversion2;
678 /* Nonzero means to use global dataflow analysis to eliminate
679 useless null pointer tests. */
681 int flag_delete_null_pointer_checks;
683 /* Nonzero means perform global CSE. */
685 int flag_gcse = 0;
687 /* Nonzero means to do the enhanced load motion during gcse, which trys
688 to hoist loads by not killing them when a store to the same location
689 is seen. */
691 int flag_gcse_lm = 1;
693 /* Nonzero means to perform store motion after gcse, which will try to
694 move stores closer to the exit block. Its not very effective without
695 flag_gcse_lm. */
697 int flag_gcse_sm = 1;
699 /* Nonzero if we want to perfrom redundant load after store elimination
700 in gcse. */
702 int flag_gcse_las = 1;
704 /* Perform target register optimization before prologue / epilogue
705 threading. */
707 int flag_branch_target_load_optimize = 0;
709 /* Perform target register optimization after prologue / epilogue
710 threading and jump2. */
712 int flag_branch_target_load_optimize2 = 0;
714 /* Nonzero means to rerun cse after loop optimization. This increases
715 compilation time about 20% and picks up a few more common expressions. */
717 int flag_rerun_cse_after_loop;
719 /* Nonzero means to run loop optimizations twice. */
721 int flag_rerun_loop_opt;
723 /* Nonzero for -finline-functions: ok to inline functions that look like
724 good inline candidates. */
726 int flag_inline_functions;
728 /* Nonzero for -fkeep-inline-functions: even if we make a function
729 go inline everywhere, keep its definition around for debugging
730 purposes. */
732 int flag_keep_inline_functions;
734 /* Nonzero means that functions will not be inlined. */
736 int flag_no_inline = 2;
738 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
739 not just because the tree inliner turned us off. */
741 int flag_really_no_inline = 2;
743 /* Nonzero means that we should emit static const variables
744 regardless of whether or not optimization is turned on. */
746 int flag_keep_static_consts = 1;
748 /* Nonzero means we should be saving declaration info into a .X file. */
750 int flag_gen_aux_info = 0;
752 /* Specified name of aux-info file. */
754 const char *aux_info_file_name;
756 /* Nonzero means make the text shared if supported. */
758 int flag_shared_data;
760 /* Nonzero means schedule into delayed branch slots if supported. */
762 int flag_delayed_branch;
764 /* Nonzero if we are compiling pure (sharable) code.
765 Value is 1 if we are doing "small" pic; value is 2 if we're doing
766 "large" pic. */
768 int flag_pic;
770 /* Nonzero if we are compiling position independent code for executable.
771 The value is 1 if we are doing "small" pic; value is 2 if we're doing
772 "large" pic. */
774 int flag_pie;
776 /* Nonzero if we are compiling code for a shared library, zero for
777 executable. */
779 int flag_shlib;
781 /* Set to the default thread-local storage (tls) model to use. */
783 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
785 /* Nonzero means generate extra code for exception handling and enable
786 exception handling. */
788 int flag_exceptions;
790 /* Nonzero means generate frame unwind info table when supported. */
792 int flag_unwind_tables = 0;
794 /* Nonzero means generate frame unwind info table exact at each insn
795 boundary. */
797 int flag_asynchronous_unwind_tables = 0;
799 /* Nonzero means don't place uninitialized global data in common storage
800 by default. */
802 int flag_no_common;
804 /* Nonzero means change certain warnings into errors.
805 Usually these are warnings about failure to conform to some standard. */
807 int flag_pedantic_errors = 0;
809 /* flag_schedule_insns means schedule insns within basic blocks (before
810 local_alloc).
811 flag_schedule_insns_after_reload means schedule insns after
812 global_alloc. */
814 int flag_schedule_insns = 0;
815 int flag_schedule_insns_after_reload = 0;
817 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
818 int flag_sched2_use_superblocks = 0;
820 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
821 scheduler. */
822 int flag_sched2_use_traces = 0;
824 /* The following flags have effect only for scheduling before register
825 allocation:
827 flag_schedule_interblock means schedule insns across basic blocks.
828 flag_schedule_speculative means allow speculative motion of non-load insns.
829 flag_schedule_speculative_load means allow speculative motion of some
830 load insns.
831 flag_schedule_speculative_load_dangerous allows speculative motion of more
832 load insns. */
834 int flag_schedule_interblock = 1;
835 int flag_schedule_speculative = 1;
836 int flag_schedule_speculative_load = 0;
837 int flag_schedule_speculative_load_dangerous = 0;
839 /* The following flags have an effect during scheduling after register
840 allocation:
842 flag_sched_stalled_insns means that insns can be moved prematurely from the queue
843 of stalled insns into the ready list.
845 flag_sched_stalled_insns_dep controls how many insn groups will be examined
846 for a dependency on a stalled insn that is candidate for premature removal
847 from the queue of stalled insns into the ready list (has an effect only if
848 the flag 'sched_stalled_insns' is set). */
850 int flag_sched_stalled_insns = 0;
851 int flag_sched_stalled_insns_dep = 1;
853 int flag_single_precision_constant;
855 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
856 by a cheaper branch on a count register. */
857 int flag_branch_on_count_reg = 1;
859 /* -finhibit-size-directive inhibits output of .size for ELF.
860 This is used only for compiling crtstuff.c,
861 and it may be extended to other effects
862 needed for crtstuff.c on other systems. */
863 int flag_inhibit_size_directive = 0;
865 /* -fverbose-asm causes extra commentary information to be produced in
866 the generated assembly code (to make it more readable). This option
867 is generally only of use to those who actually need to read the
868 generated assembly code (perhaps while debugging the compiler itself).
869 -fno-verbose-asm, the default, causes the extra information
870 to be omitted and is useful when comparing two assembler files. */
872 int flag_verbose_asm = 0;
874 /* -dA causes debug commentary information to be produced in
875 the generated assembly code (to make it more readable). This option
876 is generally only of use to those who actually need to read the
877 generated assembly code (perhaps while debugging the compiler itself).
878 Currently, this switch is only used by dwarfout.c; however, it is intended
879 to be a catchall for printing debug information in the assembler file. */
881 int flag_debug_asm = 0;
883 /* -dP causes the rtl to be emitted as a comment in assembly. */
885 int flag_dump_rtl_in_asm = 0;
887 /* Nonzero means put zero initialized data in the bss section. */
888 int flag_zero_initialized_in_bss = 1;
890 /* Tag all structures with __attribute__(packed). */
891 int flag_pack_struct = 0;
893 /* Emit code to check for stack overflow; also may cause large objects
894 to be allocated dynamically. */
895 int flag_stack_check;
897 /* When non-NULL, indicates that whenever space is allocated on the
898 stack, the resulting stack pointer must not pass this
899 address---that is, for stacks that grow downward, the stack pointer
900 must always be greater than or equal to this address; for stacks
901 that grow upward, the stack pointer must be less than this address.
902 At present, the rtx may be either a REG or a SYMBOL_REF, although
903 the support provided depends on the backend. */
904 rtx stack_limit_rtx;
906 /* 0 if pointer arguments may alias each other. True in C.
907 1 if pointer arguments may not alias each other but may alias
908 global variables.
909 2 if pointer arguments may not alias each other and may not
910 alias global variables. True in Fortran.
911 This defaults to 0 for C. */
912 int flag_argument_noalias = 0;
914 /* Nonzero if we should do (language-dependent) alias analysis.
915 Typically, this analysis will assume that expressions of certain
916 types do not alias expressions of certain other types. Only used
917 if alias analysis (in general) is enabled. */
918 int flag_strict_aliasing = 0;
920 /* Instrument functions with calls at entry and exit, for profiling. */
921 int flag_instrument_function_entry_exit = 0;
923 /* Nonzero means ignore `#ident' directives. 0 means handle them.
924 On SVR4 targets, it also controls whether or not to emit a
925 string identifying the compiler. */
927 int flag_no_ident = 0;
929 /* This will perform a peephole pass before sched2. */
930 int flag_peephole2 = 0;
932 /* This will try to guess branch probabilities. */
933 int flag_guess_branch_prob = 0;
935 /* -fcheck-bounds causes gcc to generate array bounds checks.
936 For C, C++, ObjC: defaults to off.
937 For Java: defaults to on.
938 For Fortran: defaults to off. */
939 int flag_bounds_check = 0;
941 /* This will attempt to merge constant section constants, if 1 only
942 string constants and constants from constant pool, if 2 also constant
943 variables. */
944 int flag_merge_constants = 1;
946 /* If one, renumber instruction UIDs to reduce the number of
947 unused UIDs if there are a lot of instructions. If greater than
948 one, unconditionally renumber instruction UIDs. */
949 int flag_renumber_insns = 1;
951 /* If nonzero, use the graph coloring register allocator. */
952 int flag_new_regalloc = 0;
954 /* Nonzero if we perform superblock formation. */
956 int flag_tracer = 0;
958 /* Nonzero if we perform whole unit at a time compilation. */
960 int flag_unit_at_a_time = 0;
962 /* Values of the -falign-* flags: how much to align labels in code.
963 0 means `use default', 1 means `don't align'.
964 For each variable, there is an _log variant which is the power
965 of two not less than the variable, for .align output. */
967 int align_loops;
968 int align_loops_log;
969 int align_loops_max_skip;
970 int align_jumps;
971 int align_jumps_log;
972 int align_jumps_max_skip;
973 int align_labels;
974 int align_labels_log;
975 int align_labels_max_skip;
976 int align_functions;
977 int align_functions_log;
979 /* Like align_functions_log above, but used by front-ends to force the
980 minimum function alignment. Zero means no alignment is forced. */
981 int force_align_functions_log;
983 typedef struct
985 const char *const string;
986 int *const variable;
987 const int on_value;
989 lang_independent_options;
991 /* Nonzero if signed arithmetic overflow should trap. */
992 int flag_trapv = 0;
994 /* Nonzero if signed arithmetic overflow should wrap around. */
995 int flag_wrapv = 0;
997 /* Nonzero if subexpressions must be evaluated from left-to-right. */
998 int flag_evaluation_order = 0;
1000 /* Add or remove a leading underscore from user symbols. */
1001 int flag_leading_underscore = -1;
1003 /* The user symbol prefix after having resolved same. */
1004 const char *user_label_prefix;
1006 static const param_info lang_independent_params[] = {
1007 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1008 { OPTION, DEFAULT, HELP },
1009 #include "params.def"
1010 #undef DEFPARAM
1011 { NULL, 0, NULL }
1014 /* Table of language-independent -f options.
1015 STRING is the option name. VARIABLE is the address of the variable.
1016 ON_VALUE is the value to store in VARIABLE
1017 if `-fSTRING' is seen as an option.
1018 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1020 static const lang_independent_options f_options[] =
1022 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1023 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1024 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1025 {"float-store", &flag_float_store, 1 },
1026 {"defer-pop", &flag_defer_pop, 1 },
1027 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1028 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1029 {"tracer", &flag_tracer, 1 },
1030 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1031 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1032 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1033 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1034 {"thread-jumps", &flag_thread_jumps, 1 },
1035 {"strength-reduce", &flag_strength_reduce, 1 },
1036 {"unroll-loops", &flag_unroll_loops, 1 },
1037 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1038 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1039 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1040 {"peel-loops", &flag_peel_loops, 1 },
1041 {"unswitch-loops", &flag_unswitch_loops, 1 },
1042 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1043 {"move-all-movables", &flag_move_all_movables, 1 },
1044 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1045 {"writable-strings", &flag_writable_strings, 1 },
1046 {"peephole", &flag_no_peephole, 0 },
1047 {"force-mem", &flag_force_mem, 1 },
1048 {"force-addr", &flag_force_addr, 1 },
1049 {"function-cse", &flag_no_function_cse, 0 },
1050 {"inline-functions", &flag_inline_functions, 1 },
1051 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1052 {"inline", &flag_no_inline, 0 },
1053 {"keep-static-consts", &flag_keep_static_consts, 1 },
1054 {"syntax-only", &flag_syntax_only, 1 },
1055 {"shared-data", &flag_shared_data, 1 },
1056 {"caller-saves", &flag_caller_saves, 1 },
1057 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1058 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1059 {"delayed-branch", &flag_delayed_branch, 1 },
1060 {"web", &flag_web, 1},
1061 {"gcse", &flag_gcse, 1 },
1062 {"gcse-lm", &flag_gcse_lm, 1 },
1063 {"gcse-sm", &flag_gcse_sm, 1 },
1064 {"gcse-las", &flag_gcse_las, 1 },
1065 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1066 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1067 {"loop-optimize", &flag_loop_optimize, 1 },
1068 {"crossjumping", &flag_crossjumping, 1 },
1069 {"if-conversion", &flag_if_conversion, 1 },
1070 {"if-conversion2", &flag_if_conversion2, 1 },
1071 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1072 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1073 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1074 {"schedule-insns", &flag_schedule_insns, 1 },
1075 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1076 {"sched-interblock",&flag_schedule_interblock, 1 },
1077 {"sched-spec",&flag_schedule_speculative, 1 },
1078 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1079 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1080 {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
1081 {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
1082 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1083 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1084 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1085 {"pic", &flag_pic, 1 },
1086 {"PIC", &flag_pic, 2 },
1087 {"pie", &flag_pie, 1 },
1088 {"PIE", &flag_pie, 2 },
1089 {"exceptions", &flag_exceptions, 1 },
1090 {"unwind-tables", &flag_unwind_tables, 1 },
1091 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1092 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1093 {"profile-arcs", &profile_arc_flag, 1 },
1094 {"profile-values", &flag_profile_values, 1 },
1095 {"vpt", &flag_value_profile_transformations, 1 },
1096 {"test-coverage", &flag_test_coverage, 1 },
1097 {"branch-probabilities", &flag_branch_probabilities, 1 },
1098 {"profile", &profile_flag, 1 },
1099 {"reorder-blocks", &flag_reorder_blocks, 1 },
1100 {"reorder-functions", &flag_reorder_functions, 1 },
1101 {"rename-registers", &flag_rename_registers, 1 },
1102 {"cprop-registers", &flag_cprop_registers, 1 },
1103 {"common", &flag_no_common, 0 },
1104 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1105 {"function-sections", &flag_function_sections, 1 },
1106 {"data-sections", &flag_data_sections, 1 },
1107 {"verbose-asm", &flag_verbose_asm, 1 },
1108 {"regmove", &flag_regmove, 1 },
1109 {"optimize-register-move", &flag_regmove, 1 },
1110 {"pack-struct", &flag_pack_struct, 1 },
1111 {"stack-check", &flag_stack_check, 1 },
1112 {"argument-alias", &flag_argument_noalias, 0 },
1113 {"argument-noalias", &flag_argument_noalias, 1 },
1114 {"argument-noalias-global", &flag_argument_noalias, 2 },
1115 {"strict-aliasing", &flag_strict_aliasing, 1 },
1116 {"align-loops", &align_loops, 0 },
1117 {"align-jumps", &align_jumps, 0 },
1118 {"align-labels", &align_labels, 0 },
1119 {"align-functions", &align_functions, 0 },
1120 {"merge-constants", &flag_merge_constants, 1 },
1121 {"merge-all-constants", &flag_merge_constants, 2 },
1122 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1123 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1124 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1125 {"leading-underscore", &flag_leading_underscore, 1 },
1126 {"ident", &flag_no_ident, 0 },
1127 { "peephole2", &flag_peephole2, 1 },
1128 {"finite-math-only", &flag_finite_math_only, 1 },
1129 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1130 {"math-errno", &flag_errno_math, 1 },
1131 {"trapping-math", &flag_trapping_math, 1 },
1132 {"rounding-math", &flag_rounding_math, 1 },
1133 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1134 {"signaling-nans", &flag_signaling_nans, 1 },
1135 {"bounds-check", &flag_bounds_check, 1 },
1136 {"single-precision-constant", &flag_single_precision_constant, 1 },
1137 {"time-report", &time_report, 1 },
1138 {"mem-report", &mem_report, 1 },
1139 { "trapv", &flag_trapv, 1 },
1140 { "wrapv", &flag_wrapv, 1 },
1141 { "new-ra", &flag_new_regalloc, 1 }
1144 /* Here is a table, controlled by the tm.h file, listing each -m switch
1145 and which bits in `target_switches' it should set or clear.
1146 If VALUE is positive, it is bits to set.
1147 If VALUE is negative, -VALUE is bits to clear.
1148 (The sign bit is not used so there is no confusion.) */
1150 static const struct
1152 const char *const name;
1153 const int value;
1154 const char *const description;
1156 target_switches[] = TARGET_SWITCHES;
1158 /* This table is similar, but allows the switch to have a value. */
1160 #ifdef TARGET_OPTIONS
1161 static const struct
1163 const char *const prefix;
1164 const char **const variable;
1165 const char *const description;
1166 const char *const value;
1168 target_options[] = TARGET_OPTIONS;
1169 #endif
1171 /* Nonzero means warn about function definitions that default the return type
1172 or that use a null return and have a return-type other than void. */
1174 int warn_return_type;
1176 /* Output files for assembler code (real compiler output)
1177 and debugging dumps. */
1179 FILE *asm_out_file;
1180 FILE *aux_info_file;
1181 FILE *rtl_dump_file = NULL;
1182 FILE *cgraph_dump_file = NULL;
1184 /* The current working directory of a translation. It's generally the
1185 directory from which compilation was initiated, but a preprocessed
1186 file may specify the original directory in which it was
1187 created. */
1189 static const char *src_pwd;
1191 /* Initialize src_pwd with the given string, and return true. If it
1192 was already initialized, return false. As a special case, it may
1193 be called with a NULL argument to test whether src_pwd has NOT been
1194 initialized yet. */
1196 bool
1197 set_src_pwd (const char *pwd)
1199 if (src_pwd)
1200 return false;
1202 src_pwd = xstrdup (pwd);
1203 return true;
1206 /* Return the directory from which the translation unit was initiated,
1207 in case set_src_pwd() was not called before to assign it a
1208 different value. */
1210 const char *
1211 get_src_pwd (void)
1213 if (! src_pwd)
1214 src_pwd = getpwd ();
1216 return src_pwd;
1219 /* Called when the start of a function definition is parsed,
1220 this function prints on stderr the name of the function. */
1221 void
1222 announce_function (tree decl)
1224 if (!quiet_flag)
1226 if (rtl_dump_and_exit)
1227 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1228 else
1229 verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
1230 fflush (stderr);
1231 pp_needs_newline (global_dc->printer) = true;
1232 diagnostic_set_last_function (global_dc);
1236 /* Set up a default flag_random_seed and local_tick, unless the user
1237 already specified one. */
1239 static void
1240 randomize (void)
1242 if (!flag_random_seed)
1244 unsigned HOST_WIDE_INT value;
1245 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1247 /* Get some more or less random data. */
1248 #ifdef HAVE_GETTIMEOFDAY
1250 struct timeval tv;
1252 gettimeofday (&tv, NULL);
1253 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1255 #else
1257 time_t now = time (NULL);
1259 if (now != (time_t)-1)
1260 local_tick = (unsigned) now;
1262 #endif
1263 value = local_tick ^ getpid ();
1265 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1266 flag_random_seed = random_seed;
1268 else if (!local_tick)
1269 local_tick = -1;
1273 /* Decode the string P as an integral parameter.
1274 If the string is indeed an integer return its numeric value else
1275 issue an Invalid Option error for the option PNAME and return DEFVAL.
1276 If PNAME is zero just return DEFVAL, do not call error. */
1279 read_integral_parameter (const char *p, const char *pname, const int defval)
1281 const char *endp = p;
1283 while (*endp)
1285 if (ISDIGIT (*endp))
1286 endp++;
1287 else
1288 break;
1291 if (*endp != 0)
1293 if (pname != 0)
1294 error ("invalid option argument `%s'", pname);
1295 return defval;
1298 return atoi (p);
1301 /* Return the logarithm of X, base 2, considering X unsigned,
1302 if X is a power of 2. Otherwise, returns -1.
1304 This should be used via the `exact_log2' macro. */
1307 exact_log2_wide (unsigned HOST_WIDE_INT x)
1309 int log = 0;
1310 /* Test for 0 or a power of 2. */
1311 if (x == 0 || x != (x & -x))
1312 return -1;
1313 while ((x >>= 1) != 0)
1314 log++;
1315 return log;
1318 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1319 If X is 0, return -1.
1321 This should be used via the floor_log2 macro. */
1324 floor_log2_wide (unsigned HOST_WIDE_INT x)
1326 int log = -1;
1327 while (x != 0)
1328 log++,
1329 x >>= 1;
1330 return log;
1333 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1334 into ICE messages, which is much more user friendly. In case the
1335 error printer crashes, reset the signal to prevent infinite recursion. */
1337 static void
1338 crash_signal (int signo)
1340 signal (signo, SIG_DFL);
1341 internal_error ("%s", strsignal (signo));
1344 /* Arrange to dump core on error. (The regular error message is still
1345 printed first, except in the case of abort().) */
1347 static void
1348 setup_core_dumping (void)
1350 #ifdef SIGABRT
1351 signal (SIGABRT, SIG_DFL);
1352 #endif
1353 #if defined(HAVE_SETRLIMIT)
1355 struct rlimit rlim;
1356 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1357 fatal_error ("getting core file size maximum limit: %m");
1358 rlim.rlim_cur = rlim.rlim_max;
1359 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1360 fatal_error ("setting core file size limit to maximum: %m");
1362 #endif
1363 diagnostic_abort_on_error (global_dc);
1367 /* Strip off a legitimate source ending from the input string NAME of
1368 length LEN. Rather than having to know the names used by all of
1369 our front ends, we strip off an ending of a period followed by
1370 up to five characters. (Java uses ".class".) */
1372 void
1373 strip_off_ending (char *name, int len)
1375 int i;
1376 for (i = 2; i < 6 && len > i; i++)
1378 if (name[len - i] == '.')
1380 name[len - i] = '\0';
1381 break;
1386 /* Output a quoted string. */
1388 void
1389 output_quoted_string (FILE *asm_file, const char *string)
1391 #ifdef OUTPUT_QUOTED_STRING
1392 OUTPUT_QUOTED_STRING (asm_file, string);
1393 #else
1394 char c;
1396 putc ('\"', asm_file);
1397 while ((c = *string++) != 0)
1399 if (ISPRINT (c))
1401 if (c == '\"' || c == '\\')
1402 putc ('\\', asm_file);
1403 putc (c, asm_file);
1405 else
1406 fprintf (asm_file, "\\%03o", (unsigned char) c);
1408 putc ('\"', asm_file);
1409 #endif
1412 /* Output a file name in the form wanted by System V. */
1414 void
1415 output_file_directive (FILE *asm_file, const char *input_name)
1417 int len;
1418 const char *na;
1420 if (input_name == NULL)
1421 input_name = "<stdin>";
1423 len = strlen (input_name);
1424 na = input_name + len;
1426 /* NA gets INPUT_NAME sans directory names. */
1427 while (na > input_name)
1429 if (IS_DIR_SEPARATOR (na[-1]))
1430 break;
1431 na--;
1434 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1435 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1436 #else
1437 fprintf (asm_file, "\t.file\t");
1438 output_quoted_string (asm_file, na);
1439 fputc ('\n', asm_file);
1440 #endif
1443 /* Routine to open a dump file. Return true if the dump file is enabled. */
1445 static int
1446 open_dump_file (enum dump_file_index index, tree decl)
1448 char *dump_name;
1449 const char *open_arg;
1450 char seq[16];
1452 if (! dump_file[index].enabled)
1453 return 0;
1455 timevar_push (TV_DUMP);
1456 if (rtl_dump_file != NULL)
1457 fclose (rtl_dump_file);
1459 sprintf (seq, DUMPFILE_FORMAT, index);
1461 if (! dump_file[index].initialized)
1463 /* If we've not initialized the files, do so now. */
1464 if (graph_dump_format != no_graph
1465 && dump_file[index].graph_dump_p)
1467 dump_name = concat (seq, dump_file[index].extension, NULL);
1468 clean_graph_dump_file (dump_base_name, dump_name);
1469 free (dump_name);
1471 dump_file[index].initialized = 1;
1472 open_arg = "w";
1474 else
1475 open_arg = "a";
1477 dump_name = concat (dump_base_name, seq,
1478 dump_file[index].extension, NULL);
1480 rtl_dump_file = fopen (dump_name, open_arg);
1481 if (rtl_dump_file == NULL)
1482 fatal_error ("can't open %s: %m", dump_name);
1484 free (dump_name);
1486 if (decl)
1487 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1488 (*lang_hooks.decl_printable_name) (decl, 2),
1489 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1490 ? " (hot)"
1491 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1492 ? " (unlikely executed)"
1493 : "");
1495 timevar_pop (TV_DUMP);
1496 return 1;
1499 /* Routine to close a dump file. */
1501 static void
1502 close_dump_file (enum dump_file_index index,
1503 void (*func) (FILE *, rtx),
1504 rtx insns)
1506 if (! rtl_dump_file)
1507 return;
1509 timevar_push (TV_DUMP);
1510 if (insns
1511 && graph_dump_format != no_graph
1512 && dump_file[index].graph_dump_p)
1514 char seq[16];
1515 char *suffix;
1517 sprintf (seq, DUMPFILE_FORMAT, index);
1518 suffix = concat (seq, dump_file[index].extension, NULL);
1519 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1520 free (suffix);
1523 if (func && insns)
1524 func (rtl_dump_file, insns);
1526 fflush (rtl_dump_file);
1527 fclose (rtl_dump_file);
1529 rtl_dump_file = NULL;
1530 timevar_pop (TV_DUMP);
1533 /* Do any final processing required for the declarations in VEC, of
1534 which there are LEN. We write out inline functions and variables
1535 that have been deferred until this point, but which are required.
1536 Returns nonzero if anything was put out. */
1539 wrapup_global_declarations (tree *vec, int len)
1541 tree decl;
1542 int i;
1543 int reconsider;
1544 int output_something = 0;
1546 for (i = 0; i < len; i++)
1548 decl = vec[i];
1550 /* We're not deferring this any longer. Assignment is
1551 conditional to avoid needlessly dirtying PCH pages. */
1552 if (DECL_DEFER_OUTPUT (decl) != 0)
1553 DECL_DEFER_OUTPUT (decl) = 0;
1555 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1556 (*lang_hooks.finish_incomplete_decl) (decl);
1559 /* Now emit any global variables or functions that we have been
1560 putting off. We need to loop in case one of the things emitted
1561 here references another one which comes earlier in the list. */
1564 reconsider = 0;
1565 for (i = 0; i < len; i++)
1567 decl = vec[i];
1569 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1570 continue;
1572 /* Don't write out static consts, unless we still need them.
1574 We also keep static consts if not optimizing (for debugging),
1575 unless the user specified -fno-keep-static-consts.
1576 ??? They might be better written into the debug information.
1577 This is possible when using DWARF.
1579 A language processor that wants static constants to be always
1580 written out (even if it is not used) is responsible for
1581 calling rest_of_decl_compilation itself. E.g. the C front-end
1582 calls rest_of_decl_compilation from finish_decl.
1583 One motivation for this is that is conventional in some
1584 environments to write things like:
1585 static const char rcsid[] = "... version string ...";
1586 intending to force the string to be in the executable.
1588 A language processor that would prefer to have unneeded
1589 static constants "optimized away" would just defer writing
1590 them out until here. E.g. C++ does this, because static
1591 constants are often defined in header files.
1593 ??? A tempting alternative (for both C and C++) would be
1594 to force a constant to be written if and only if it is
1595 defined in a main file, as opposed to an include file. */
1597 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1599 bool needed = 1;
1601 if (flag_unit_at_a_time
1602 && cgraph_varpool_node (decl)->finalized)
1603 needed = 0;
1604 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1605 && (TREE_USED (decl)
1606 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1607 /* needed */;
1608 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1609 /* needed */;
1610 else if (DECL_COMDAT (decl))
1611 needed = 0;
1612 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1613 && (optimize || !flag_keep_static_consts
1614 || DECL_ARTIFICIAL (decl)))
1615 needed = 0;
1617 if (needed)
1619 reconsider = 1;
1620 rest_of_decl_compilation (decl, NULL, 1, 1);
1624 if (TREE_CODE (decl) == FUNCTION_DECL
1625 && DECL_INITIAL (decl) != 0
1626 && DECL_SAVED_INSNS (decl) != 0
1627 && DECL_SAVED_INSNS (decl)->saved_for_inline
1628 && (flag_keep_inline_functions
1629 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1630 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1632 reconsider = 1;
1633 output_inline_function (decl);
1637 if (reconsider)
1638 output_something = 1;
1640 while (reconsider);
1642 return output_something;
1645 /* Issue appropriate warnings for the global declarations in VEC (of
1646 which there are LEN). Output debugging information for them. */
1648 void
1649 check_global_declarations (tree *vec, int len)
1651 tree decl;
1652 int i;
1654 for (i = 0; i < len; i++)
1656 decl = vec[i];
1658 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1659 && ! TREE_ASM_WRITTEN (decl))
1660 /* Cancel the RTL for this decl so that, if debugging info
1661 output for global variables is still to come,
1662 this one will be omitted. */
1663 SET_DECL_RTL (decl, NULL_RTX);
1665 /* Warn about any function
1666 declared static but not defined.
1667 We don't warn about variables,
1668 because many programs have static variables
1669 that exist only to get some text into the object file. */
1670 if (TREE_CODE (decl) == FUNCTION_DECL
1671 && (warn_unused_function
1672 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1673 && DECL_INITIAL (decl) == 0
1674 && DECL_EXTERNAL (decl)
1675 && ! DECL_ARTIFICIAL (decl)
1676 && ! TREE_PUBLIC (decl))
1678 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1679 pedwarn ("%J'%F' used but never defined", decl, decl);
1680 else
1681 warning ("%J'%F' declared `static' but never defined", decl, decl);
1682 /* This symbol is effectively an "extern" declaration now. */
1683 TREE_PUBLIC (decl) = 1;
1684 assemble_external (decl);
1687 /* Warn about static fns or vars defined but not used. */
1688 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1689 /* We don't warn about "static const" variables because the
1690 "rcs_id" idiom uses that construction. */
1691 || (warn_unused_variable
1692 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
1693 && ! DECL_IN_SYSTEM_HEADER (decl)
1694 && ! TREE_USED (decl)
1695 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1696 to handle multiple external decls in different scopes. */
1697 && ! TREE_USED (DECL_NAME (decl))
1698 && ! DECL_EXTERNAL (decl)
1699 && ! TREE_PUBLIC (decl)
1700 /* A volatile variable might be used in some non-obvious way. */
1701 && ! TREE_THIS_VOLATILE (decl)
1702 /* Global register variables must be declared to reserve them. */
1703 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1704 /* Otherwise, ask the language. */
1705 && (*lang_hooks.decls.warn_unused_global) (decl))
1706 warning ("%J'%D' defined but not used", decl, decl);
1708 /* Avoid confusing the debug information machinery when there are
1709 errors. */
1710 if (errorcount == 0 && sorrycount == 0)
1712 timevar_push (TV_SYMOUT);
1713 (*debug_hooks->global_decl) (decl);
1714 timevar_pop (TV_SYMOUT);
1719 /* Warn about a use of an identifier which was marked deprecated. */
1720 void
1721 warn_deprecated_use (tree node)
1723 if (node == 0 || !warn_deprecated_decl)
1724 return;
1726 if (DECL_P (node))
1727 warning ("`%s' is deprecated (declared at %s:%d)",
1728 IDENTIFIER_POINTER (DECL_NAME (node)),
1729 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1730 else if (TYPE_P (node))
1732 const char *what = NULL;
1733 tree decl = TYPE_STUB_DECL (node);
1735 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1736 what = IDENTIFIER_POINTER (TYPE_NAME (node));
1737 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1738 && DECL_NAME (TYPE_NAME (node)))
1739 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1741 if (what)
1743 if (decl)
1744 warning ("`%s' is deprecated (declared at %s:%d)", what,
1745 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1746 else
1747 warning ("`%s' is deprecated", what);
1749 else if (decl)
1750 warning ("type is deprecated (declared at %s:%d)",
1751 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1752 else
1753 warning ("type is deprecated");
1757 /* Save the current INPUT_LOCATION on the top entry in the
1758 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1759 INPUT_LOCATION accordingly. */
1761 void
1762 push_srcloc (const char *file, int line)
1764 struct file_stack *fs;
1766 fs = xmalloc (sizeof (struct file_stack));
1767 fs->location = input_location;
1768 fs->next = input_file_stack;
1769 input_filename = file;
1770 input_line = line;
1771 input_file_stack = fs;
1772 input_file_stack_tick++;
1775 /* Pop the top entry off the stack of presently open source files.
1776 Restore the INPUT_LOCATION from the new topmost entry on the
1777 stack. */
1779 void
1780 pop_srcloc (void)
1782 struct file_stack *fs;
1784 fs = input_file_stack;
1785 input_location = fs->location;
1786 input_file_stack = fs->next;
1787 free (fs);
1788 input_file_stack_tick++;
1791 /* Compile an entire translation unit. Write a file of assembly
1792 output and various debugging dumps. */
1794 static void
1795 compile_file (void)
1797 /* Initialize yet another pass. */
1799 init_final (main_input_filename);
1800 coverage_init (aux_base_name);
1802 timevar_push (TV_PARSE);
1804 /* Call the parser, which parses the entire file (calling
1805 rest_of_compilation for each function). */
1806 (*lang_hooks.parse_file) (set_yydebug);
1808 /* In case there were missing block closers,
1809 get us back to the global binding level. */
1810 (*lang_hooks.clear_binding_stack) ();
1812 /* Compilation is now finished except for writing
1813 what's left of the symbol table output. */
1814 timevar_pop (TV_PARSE);
1816 if (flag_syntax_only)
1817 return;
1819 (*lang_hooks.decls.final_write_globals)();
1821 cgraph_varpool_assemble_pending_decls ();
1823 /* This must occur after the loop to output deferred functions.
1824 Else the coverage initializer would not be emitted if all the
1825 functions in this compilation unit were deferred. */
1826 coverage_finish ();
1828 /* Write out any pending weak symbol declarations. */
1830 weak_finish ();
1832 /* Do dbx symbols. */
1833 timevar_push (TV_SYMOUT);
1835 #ifdef DWARF2_UNWIND_INFO
1836 if (dwarf2out_do_frame ())
1837 dwarf2out_frame_finish ();
1838 #endif
1840 (*debug_hooks->finish) (main_input_filename);
1841 timevar_pop (TV_SYMOUT);
1843 /* Output some stuff at end of file if nec. */
1845 dw2_output_indirect_constants ();
1847 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1849 timevar_push (TV_DUMP);
1850 open_dump_file (DFI_bp, NULL);
1852 end_branch_prob ();
1854 close_dump_file (DFI_bp, NULL, NULL_RTX);
1855 timevar_pop (TV_DUMP);
1858 targetm.asm_out.file_end ();
1860 /* Attach a special .ident directive to the end of the file to identify
1861 the version of GCC which compiled this code. The format of the .ident
1862 string is patterned after the ones produced by native SVR4 compilers. */
1863 #ifdef IDENT_ASM_OP
1864 if (!flag_no_ident)
1865 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1866 IDENT_ASM_OP, version_string);
1867 #endif
1869 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1871 timevar_push (TV_DUMP);
1872 dump_combine_total_stats (rtl_dump_file);
1873 close_dump_file (DFI_combine, NULL, NULL_RTX);
1874 timevar_pop (TV_DUMP);
1878 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1879 and TYPE_DECL nodes.
1881 This does nothing for local (non-static) variables, unless the
1882 variable is a register variable with an ASMSPEC. In that case, or
1883 if the variable is not an automatic, it sets up the RTL and
1884 outputs any assembler code (label definition, storage allocation
1885 and initialization).
1887 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1888 the assembler symbol name to be used. TOP_LEVEL is nonzero
1889 if this declaration is not within a function. */
1891 void
1892 rest_of_decl_compilation (tree decl,
1893 const char *asmspec,
1894 int top_level,
1895 int at_end)
1897 /* We deferred calling assemble_alias so that we could collect
1898 other attributes such as visibility. Emit the alias now. */
1900 tree alias;
1901 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1902 if (alias)
1904 alias = TREE_VALUE (TREE_VALUE (alias));
1905 alias = get_identifier (TREE_STRING_POINTER (alias));
1906 assemble_alias (decl, alias);
1910 /* Forward declarations for nested functions are not "external",
1911 but we need to treat them as if they were. */
1912 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1913 || TREE_CODE (decl) == FUNCTION_DECL)
1915 timevar_push (TV_VARCONST);
1917 if (asmspec)
1918 make_decl_rtl (decl, asmspec);
1920 /* Don't output anything when a tentative file-scope definition
1921 is seen. But at end of compilation, do output code for them.
1923 We do output all variables when unit-at-a-time is active and rely on
1924 callgraph code to defer them except for forward declarations
1925 (see gcc.c-torture/compile/920624-1.c) */
1926 if ((at_end
1927 || !DECL_DEFER_OUTPUT (decl)
1928 || (flag_unit_at_a_time && DECL_INITIAL (decl)))
1929 && !DECL_EXTERNAL (decl))
1931 if (flag_unit_at_a_time && !cgraph_global_info_ready
1932 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1933 cgraph_varpool_finalize_decl (decl);
1934 else
1935 assemble_variable (decl, top_level, at_end, 0);
1938 #ifdef ASM_FINISH_DECLARE_OBJECT
1939 if (decl == last_assemble_variable_decl)
1941 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1942 top_level, at_end);
1944 #endif
1946 timevar_pop (TV_VARCONST);
1948 else if (DECL_REGISTER (decl) && asmspec != 0)
1950 if (decode_reg_name (asmspec) >= 0)
1952 SET_DECL_RTL (decl, NULL_RTX);
1953 make_decl_rtl (decl, asmspec);
1955 else
1957 error ("invalid register name `%s' for register variable", asmspec);
1958 DECL_REGISTER (decl) = 0;
1959 if (!top_level)
1960 expand_decl (decl);
1963 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1964 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1965 && TREE_CODE (decl) == TYPE_DECL)
1967 timevar_push (TV_SYMOUT);
1968 dbxout_symbol (decl, 0);
1969 timevar_pop (TV_SYMOUT);
1971 #endif
1972 #ifdef SDB_DEBUGGING_INFO
1973 else if (write_symbols == SDB_DEBUG && top_level
1974 && TREE_CODE (decl) == TYPE_DECL)
1976 timevar_push (TV_SYMOUT);
1977 sdbout_symbol (decl, 0);
1978 timevar_pop (TV_SYMOUT);
1980 #endif
1981 #ifdef DWARF2_DEBUGGING_INFO
1982 else if ((write_symbols == DWARF2_DEBUG
1983 || write_symbols == VMS_AND_DWARF2_DEBUG)
1984 && top_level
1985 && TREE_CODE (decl) == TYPE_DECL)
1987 timevar_push (TV_SYMOUT);
1988 dwarf2out_decl (decl);
1989 timevar_pop (TV_SYMOUT);
1991 #endif
1994 /* Called after finishing a record, union or enumeral type. */
1996 void
1997 rest_of_type_compilation (
1998 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
1999 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
2000 tree type,
2001 int toplev
2002 #else
2003 tree type ATTRIBUTE_UNUSED,
2004 int toplev ATTRIBUTE_UNUSED
2005 #endif
2008 /* Avoid confusing the debug information machinery when there are
2009 errors. */
2010 if (errorcount != 0 || sorrycount != 0)
2011 return;
2013 timevar_push (TV_SYMOUT);
2014 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2015 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2016 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2017 #endif
2018 #ifdef SDB_DEBUGGING_INFO
2019 if (write_symbols == SDB_DEBUG)
2020 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2021 #endif
2022 #ifdef DWARF2_DEBUGGING_INFO
2023 if ((write_symbols == DWARF2_DEBUG
2024 || write_symbols == VMS_AND_DWARF2_DEBUG)
2025 && toplev)
2026 dwarf2out_decl (TYPE_STUB_DECL (type));
2027 #endif
2028 timevar_pop (TV_SYMOUT);
2031 /* Turn the RTL into assembly. */
2032 static void
2033 rest_of_handle_final (tree decl, rtx insns)
2035 timevar_push (TV_FINAL);
2037 rtx x;
2038 const char *fnname;
2040 /* Get the function's name, as described by its RTL. This may be
2041 different from the DECL_NAME name used in the source file. */
2043 x = DECL_RTL (decl);
2044 if (GET_CODE (x) != MEM)
2045 abort ();
2046 x = XEXP (x, 0);
2047 if (GET_CODE (x) != SYMBOL_REF)
2048 abort ();
2049 fnname = XSTR (x, 0);
2051 assemble_start_function (decl, fnname);
2052 final_start_function (insns, asm_out_file, optimize);
2053 final (insns, asm_out_file, optimize, 0);
2054 final_end_function ();
2056 #ifdef IA64_UNWIND_INFO
2057 /* ??? The IA-64 ".handlerdata" directive must be issued before
2058 the ".endp" directive that closes the procedure descriptor. */
2059 output_function_exception_table ();
2060 #endif
2062 assemble_end_function (decl, fnname);
2064 #ifndef IA64_UNWIND_INFO
2065 /* Otherwise, it feels unclean to switch sections in the middle. */
2066 output_function_exception_table ();
2067 #endif
2069 if (! quiet_flag)
2070 fflush (asm_out_file);
2072 /* Release all memory allocated by flow. */
2073 free_basic_block_vars (0);
2075 /* Release all memory held by regsets now. */
2076 regset_release_memory ();
2078 timevar_pop (TV_FINAL);
2080 ggc_collect ();
2083 #ifdef DELAY_SLOTS
2084 /* Run delay slot optimization. */
2085 static void
2086 rest_of_handle_delay_slots (tree decl, rtx insns)
2088 timevar_push (TV_DBR_SCHED);
2089 open_dump_file (DFI_dbr, decl);
2091 dbr_schedule (insns, rtl_dump_file);
2093 close_dump_file (DFI_dbr, print_rtl, insns);
2094 timevar_pop (TV_DBR_SCHED);
2096 ggc_collect ();
2098 #endif
2100 #ifdef STACK_REGS
2101 /* Convert register usage from flat register file usage to a stack
2102 register file. */
2103 static void
2104 rest_of_handle_stack_regs (tree decl, rtx insns)
2106 #if defined (HAVE_ATTR_length)
2107 /* If flow2 creates new instructions which need splitting
2108 and scheduling after reload is not done, they might not be
2109 split until final which doesn't allow splitting
2110 if HAVE_ATTR_length. */
2111 #ifdef INSN_SCHEDULING
2112 if (optimize && !flag_schedule_insns_after_reload)
2113 #else
2114 if (optimize)
2115 #endif
2117 timevar_push (TV_SHORTEN_BRANCH);
2118 split_all_insns (1);
2119 timevar_pop (TV_SHORTEN_BRANCH);
2121 #endif
2123 timevar_push (TV_REG_STACK);
2124 open_dump_file (DFI_stack, decl);
2126 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2128 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2129 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2130 && flag_reorder_blocks)
2132 reorder_basic_blocks ();
2133 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2137 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2138 timevar_pop (TV_REG_STACK);
2140 ggc_collect ();
2142 #endif
2145 /* Machine independent reorg pass. */
2146 static void
2147 rest_of_handle_machine_reorg (tree decl, rtx insns)
2149 timevar_push (TV_MACH_DEP);
2150 open_dump_file (DFI_mach, decl);
2152 (*targetm.machine_dependent_reorg) ();
2154 close_dump_file (DFI_mach, print_rtl, insns);
2155 timevar_pop (TV_MACH_DEP);
2157 ggc_collect ();
2161 /* Run new register allocator. Return TRUE if we must exit
2162 rest_of_compilation upon return. */
2163 static bool
2164 rest_of_handle_new_regalloc (tree decl, rtx insns)
2166 int failure;
2168 delete_trivially_dead_insns (insns, max_reg_num ());
2169 reg_alloc ();
2171 timevar_pop (TV_LOCAL_ALLOC);
2172 if (dump_file[DFI_lreg].enabled)
2174 timevar_push (TV_DUMP);
2176 close_dump_file (DFI_lreg, NULL, NULL);
2177 timevar_pop (TV_DUMP);
2180 /* XXX clean up the whole mess to bring live info in shape again. */
2181 timevar_push (TV_GLOBAL_ALLOC);
2182 open_dump_file (DFI_greg, decl);
2184 build_insn_chain (insns);
2185 failure = reload (insns, 0);
2187 timevar_pop (TV_GLOBAL_ALLOC);
2189 if (dump_file[DFI_greg].enabled)
2191 timevar_push (TV_DUMP);
2193 dump_global_regs (rtl_dump_file);
2195 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2196 timevar_pop (TV_DUMP);
2199 if (failure)
2200 return true;
2202 reload_completed = 1;
2204 return false;
2207 /* Run old register allocator. Return TRUE if we must exit
2208 rest_of_compilation upon return. */
2209 static bool
2210 rest_of_handle_old_regalloc (tree decl, rtx insns)
2212 int failure;
2213 int rebuild_notes;
2215 /* Allocate the reg_renumber array. */
2216 allocate_reg_info (max_regno, FALSE, TRUE);
2218 /* And the reg_equiv_memory_loc array. */
2219 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2221 allocate_initial_values (reg_equiv_memory_loc);
2223 regclass (insns, max_reg_num (), rtl_dump_file);
2224 rebuild_notes = local_alloc ();
2226 timevar_pop (TV_LOCAL_ALLOC);
2228 /* Local allocation may have turned an indirect jump into a direct
2229 jump. If so, we must rebuild the JUMP_LABEL fields of jumping
2230 instructions. */
2231 if (rebuild_notes)
2233 timevar_push (TV_JUMP);
2235 rebuild_jump_labels (insns);
2236 purge_all_dead_edges (0);
2238 timevar_pop (TV_JUMP);
2241 if (dump_file[DFI_lreg].enabled)
2243 timevar_push (TV_DUMP);
2245 dump_flow_info (rtl_dump_file);
2246 dump_local_alloc (rtl_dump_file);
2248 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2249 timevar_pop (TV_DUMP);
2252 ggc_collect ();
2254 timevar_push (TV_GLOBAL_ALLOC);
2255 open_dump_file (DFI_greg, decl);
2257 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2258 pass fixing up any insns that are invalid. */
2260 if (optimize)
2261 failure = global_alloc (rtl_dump_file);
2262 else
2264 build_insn_chain (insns);
2265 failure = reload (insns, 0);
2268 timevar_pop (TV_GLOBAL_ALLOC);
2270 if (dump_file[DFI_greg].enabled)
2272 timevar_push (TV_DUMP);
2274 dump_global_regs (rtl_dump_file);
2276 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2277 timevar_pop (TV_DUMP);
2280 return failure;
2283 /* Run the regrename and cprop passes. */
2284 static void
2285 rest_of_handle_regrename (tree decl, rtx insns)
2287 timevar_push (TV_RENAME_REGISTERS);
2288 open_dump_file (DFI_rnreg, decl);
2290 if (flag_rename_registers)
2291 regrename_optimize ();
2292 if (flag_cprop_registers)
2293 copyprop_hardreg_forward ();
2295 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2296 timevar_pop (TV_RENAME_REGISTERS);
2299 /* Reorder basic blocks. */
2300 static void
2301 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2303 bool changed;
2304 open_dump_file (DFI_bbro, decl);
2306 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2307 splitting possibly introduced more crossjumping opportunities. */
2308 changed = cleanup_cfg (CLEANUP_EXPENSIVE
2309 | (!HAVE_conditional_execution
2310 ? CLEANUP_UPDATE_LIFE : 0));
2312 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2313 tracer ();
2314 if (flag_reorder_blocks)
2315 reorder_basic_blocks ();
2316 if (flag_reorder_blocks
2317 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2318 changed |= cleanup_cfg (CLEANUP_EXPENSIVE
2319 | (!HAVE_conditional_execution
2320 ? CLEANUP_UPDATE_LIFE : 0));
2322 /* On conditional execution targets we can not update the life cheaply, so
2323 we deffer the updating to after both cleanups. This may lose some cases
2324 but should not be terribly bad. */
2325 if (changed && HAVE_conditional_execution)
2326 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2327 PROP_DEATH_NOTES | PROP_REG_INFO);
2328 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2331 #ifdef INSN_SCHEDULING
2332 /* Run instruction scheduler. */
2333 static void
2334 rest_of_handle_sched (tree decl, rtx insns)
2336 timevar_push (TV_SCHED);
2338 /* Print function header into sched dump now
2339 because doing the sched analysis makes some of the dump. */
2340 if (optimize > 0 && flag_schedule_insns)
2342 open_dump_file (DFI_sched, decl);
2344 /* Do control and data sched analysis,
2345 and write some of the results to dump file. */
2347 schedule_insns (rtl_dump_file);
2349 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2351 timevar_pop (TV_SCHED);
2353 ggc_collect ();
2356 /* Run second scheduling pass after reload. */
2357 static void
2358 rest_of_handle_sched2 (tree decl, rtx insns)
2360 timevar_push (TV_SCHED2);
2361 open_dump_file (DFI_sched2, decl);
2363 /* Do control and data sched analysis again,
2364 and write some more of the results to dump file. */
2366 split_all_insns (1);
2368 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2370 schedule_ebbs (rtl_dump_file);
2371 /* No liveness updating code yet, but it should be easy to do.
2372 reg-stack recompute the liveness when needed for now. */
2373 count_or_remove_death_notes (NULL, 1);
2374 cleanup_cfg (CLEANUP_EXPENSIVE);
2376 else
2377 schedule_insns (rtl_dump_file);
2379 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2380 timevar_pop (TV_SCHED2);
2382 ggc_collect ();
2384 #endif
2386 /* Register allocation pre-pass, to reduce number of moves necessary
2387 for two-address machines. */
2388 static void
2389 rest_of_handle_regmove (tree decl, rtx insns)
2391 timevar_push (TV_REGMOVE);
2392 open_dump_file (DFI_regmove, decl);
2394 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2396 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2397 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2398 timevar_pop (TV_REGMOVE);
2400 ggc_collect ();
2403 /* Run tracer. */
2404 static void
2405 rest_of_handle_tracer (tree decl, rtx insns)
2407 open_dump_file (DFI_tracer, decl);
2408 if (rtl_dump_file)
2409 dump_flow_info (rtl_dump_file);
2410 tracer ();
2411 cleanup_cfg (CLEANUP_EXPENSIVE);
2412 reg_scan (insns, max_reg_num (), 0);
2413 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2416 /* If-conversion and CFG cleanup. */
2417 static void
2418 rest_of_handle_if_conversion (tree decl, rtx insns)
2420 open_dump_file (DFI_ce1, decl);
2421 if (flag_if_conversion)
2423 timevar_push (TV_IFCVT);
2424 if (rtl_dump_file)
2425 dump_flow_info (rtl_dump_file);
2426 cleanup_cfg (CLEANUP_EXPENSIVE);
2427 reg_scan (insns, max_reg_num (), 0);
2428 if_convert (0);
2429 timevar_pop (TV_IFCVT);
2431 timevar_push (TV_JUMP);
2432 cleanup_cfg (CLEANUP_EXPENSIVE);
2433 reg_scan (insns, max_reg_num (), 0);
2434 timevar_pop (TV_JUMP);
2435 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2438 /* Rerun if-conversion, as combine may have simplified things enough
2439 to now meet sequence length restrictions. */
2440 static void
2441 rest_of_handle_if_after_combine (tree decl, rtx insns)
2443 timevar_push (TV_IFCVT);
2444 open_dump_file (DFI_ce2, decl);
2446 no_new_pseudos = 0;
2447 if_convert (1);
2448 no_new_pseudos = 1;
2450 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2451 timevar_pop (TV_IFCVT);
2454 static void
2455 rest_of_handle_web (tree decl, rtx insns)
2457 open_dump_file (DFI_web, decl);
2458 timevar_push (TV_WEB);
2459 web_main ();
2460 delete_trivially_dead_insns (insns, max_reg_num ());
2461 cleanup_cfg (CLEANUP_EXPENSIVE);
2463 timevar_pop (TV_WEB);
2464 close_dump_file (DFI_web, print_rtl_with_bb, insns);
2465 reg_scan (get_insns (), max_reg_num (), 0);
2468 /* Do branch profiling and static profile estimation passes. */
2469 static void
2470 rest_of_handle_branch_prob (tree decl, rtx insns)
2472 struct loops loops;
2474 timevar_push (TV_BRANCH_PROB);
2475 open_dump_file (DFI_bp, decl);
2477 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2478 branch_prob ();
2480 /* Discover and record the loop depth at the head of each basic
2481 block. The loop infrastructure does the real job for us. */
2482 flow_loops_find (&loops, LOOP_TREE);
2484 if (rtl_dump_file)
2485 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2487 /* Estimate using heuristics if no profiling info is available. */
2488 if (flag_guess_branch_prob)
2489 estimate_probability (&loops);
2491 flow_loops_free (&loops);
2492 free_dominance_info (CDI_DOMINATORS);
2493 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2494 timevar_pop (TV_BRANCH_PROB);
2497 /* Do optimizations based on expression value profiles. */
2498 static void
2499 rest_of_handle_value_profile_transformations (tree decl, rtx insns)
2501 open_dump_file (DFI_vpt, decl);
2502 timevar_push (TV_VPT);
2504 if (value_profile_transformations ())
2505 cleanup_cfg (CLEANUP_EXPENSIVE);
2507 timevar_pop (TV_VPT);
2508 close_dump_file (DFI_vpt, print_rtl_with_bb, insns);
2511 /* Do control and data flow analysis; write some of the results to the
2512 dump file. */
2513 static void
2514 rest_of_handle_cfg (tree decl, rtx insns)
2516 open_dump_file (DFI_cfg, decl);
2517 if (rtl_dump_file)
2518 dump_flow_info (rtl_dump_file);
2519 if (optimize)
2520 cleanup_cfg (CLEANUP_EXPENSIVE
2521 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2523 /* It may make more sense to mark constant functions after dead code is
2524 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2525 may insert code making function non-constant, but we still must consider
2526 it as constant, otherwise -fbranch-probabilities will not read data back.
2528 life_analysis rarely eliminates modification of external memory.
2530 if (optimize)
2532 /* Alias analysis depends on this information and mark_constant_function
2533 depends on alias analysis. */
2534 reg_scan (insns, max_reg_num (), 1);
2535 mark_constant_function ();
2538 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2541 /* Purge addressofs. */
2542 static void
2543 rest_of_handle_addressof (tree decl, rtx insns)
2545 open_dump_file (DFI_addressof, decl);
2547 purge_addressof (insns);
2548 if (optimize && purge_all_dead_edges (0))
2549 delete_unreachable_blocks ();
2550 reg_scan (insns, max_reg_num (), 1);
2552 close_dump_file (DFI_addressof, print_rtl, insns);
2555 /* We may have potential sibling or tail recursion sites. Select one
2556 (of possibly multiple) methods of performing the call. */
2557 static void
2558 rest_of_handle_sibling_calls (rtx insns)
2560 rtx insn;
2561 optimize_sibling_and_tail_recursive_calls ();
2563 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2564 free_bb_for_insn ();
2565 find_exception_handler_labels ();
2566 rebuild_jump_labels (insns);
2567 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2569 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2570 notes before simplifying cfg and we must do lowering after sibcall
2571 that unhides parts of RTL chain and cleans up the CFG.
2573 Until sibcall is replaced by tree-level optimizer, lets just
2574 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2575 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2576 if (GET_CODE (insn) == NOTE
2577 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2578 delete_insn (insn);
2580 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2583 /* Perform jump bypassing and control flow optimizations. */
2584 static void
2585 rest_of_handle_jump_bypass (tree decl, rtx insns)
2587 timevar_push (TV_BYPASS);
2588 open_dump_file (DFI_bypass, decl);
2590 cleanup_cfg (CLEANUP_EXPENSIVE);
2591 reg_scan (insns, max_reg_num (), 1);
2593 if (bypass_jumps (rtl_dump_file))
2595 rebuild_jump_labels (insns);
2596 cleanup_cfg (CLEANUP_EXPENSIVE);
2597 delete_trivially_dead_insns (insns, max_reg_num ());
2600 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2601 timevar_pop (TV_BYPASS);
2603 ggc_collect ();
2605 #ifdef ENABLE_CHECKING
2606 verify_flow_info ();
2607 #endif
2610 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2611 if we must exit rest_of_compilation upon return. */
2612 static bool
2613 rest_of_handle_inlining (tree decl)
2615 rtx insns;
2616 int inlinable = 0;
2617 tree parent;
2618 const char *lose;
2620 /* If we are reconsidering an inline function at the end of
2621 compilation, skip the stuff for making it inline. */
2622 if (cfun->rtl_inline_init)
2623 return 0;
2624 cfun->rtl_inline_init = 1;
2626 /* If this is nested inside an inlined external function, pretend
2627 it was only declared. Since we cannot inline such functions,
2628 generating code for this one is not only not necessary but will
2629 confuse some debugging output writers. */
2630 for (parent = DECL_CONTEXT (current_function_decl);
2631 parent != NULL_TREE;
2632 parent = get_containing_scope (parent))
2633 if (TREE_CODE (parent) == FUNCTION_DECL
2634 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2636 DECL_INITIAL (decl) = 0;
2637 return true;
2639 else if (TYPE_P (parent))
2640 /* A function in a local class should be treated normally. */
2641 break;
2643 /* If requested, consider whether to make this function inline. */
2644 if ((DECL_INLINE (decl) && !flag_no_inline)
2645 || flag_inline_functions)
2647 timevar_push (TV_INTEGRATION);
2648 lose = function_cannot_inline_p (decl);
2649 timevar_pop (TV_INTEGRATION);
2650 if (lose || ! optimize)
2652 if (warn_inline && lose && DECL_INLINE (decl))
2654 char *msg = concat ("%J", lose, NULL);
2655 warning (msg, decl);
2656 free (msg);
2658 DECL_ABSTRACT_ORIGIN (decl) = 0;
2659 /* Don't really compile an extern inline function.
2660 If we can't make it inline, pretend
2661 it was only declared. */
2662 if (DECL_EXTERNAL (decl))
2664 DECL_INITIAL (decl) = 0;
2665 return true;
2668 else
2669 inlinable = DECL_INLINE (decl) = 1;
2672 insns = get_insns ();
2674 /* Dump the rtl code if we are dumping rtl. */
2676 if (open_dump_file (DFI_rtl, decl))
2678 if (DECL_SAVED_INSNS (decl) && DECL_SAVED_INSNS (decl)->saved_for_inline)
2679 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2680 close_dump_file (DFI_rtl, print_rtl, insns);
2683 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2684 sorts of eh initialization. Delay this until after the
2685 initial rtl dump so that we can see the original nesting. */
2686 convert_from_eh_region_ranges ();
2688 /* If function is inline, and we don't yet know whether to
2689 compile it by itself, defer decision till end of compilation.
2690 wrapup_global_declarations will (indirectly) call
2691 rest_of_compilation again for those functions that need to
2692 be output. Also defer those functions that we are supposed
2693 to defer. */
2695 if (inlinable
2696 || (DECL_INLINE (decl)
2697 /* Egad. This RTL deferral test conflicts with Fortran assumptions
2698 for unreferenced symbols. See g77.f-torture/execute/980520-1.f.
2699 But removing this line from the check breaks all languages that
2700 use the call graph to output symbols. This hard-coded check is
2701 the least invasive work-around. */
2702 && (flag_inline_functions
2703 || strcmp (lang_hooks.name, "GNU F77") == 0)
2704 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2705 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2706 && ! flag_keep_inline_functions)
2707 || DECL_EXTERNAL (decl))))
2708 DECL_DEFER_OUTPUT (decl) = 1;
2710 if (DECL_INLINE (decl))
2711 /* DWARF wants separate debugging info for abstract and
2712 concrete instances of all inline functions, including those
2713 declared inline but not inlined, and those inlined even
2714 though they weren't declared inline. Conveniently, that's
2715 what DECL_INLINE means at this point. */
2716 (*debug_hooks->deferred_inline_function) (decl);
2718 if (DECL_DEFER_OUTPUT (decl))
2720 /* If -Wreturn-type, we have to do a bit of compilation. We just
2721 want to call cleanup the cfg to figure out whether or not we can
2722 fall off the end of the function; we do the minimum amount of
2723 work necessary to make that safe. */
2724 if (warn_return_type)
2726 int saved_optimize = optimize;
2728 optimize = 0;
2729 rebuild_jump_labels (insns);
2730 find_exception_handler_labels ();
2731 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2732 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2733 optimize = saved_optimize;
2735 /* CFG is no longer maintained up-to-date. */
2736 free_bb_for_insn ();
2739 set_nothrow_function_flags ();
2740 if (current_function_nothrow)
2741 /* Now we know that this can't throw; set the flag for the benefit
2742 of other functions later in this translation unit. */
2743 TREE_NOTHROW (current_function_decl) = 1;
2745 timevar_push (TV_INTEGRATION);
2746 save_for_inline (decl);
2747 timevar_pop (TV_INTEGRATION);
2748 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2749 return true;
2752 /* If specified extern inline but we aren't inlining it, we are
2753 done. This goes for anything that gets here with DECL_EXTERNAL
2754 set, not just things with DECL_INLINE. */
2755 return (bool) DECL_EXTERNAL (decl);
2758 /* Try to identify useless null pointer tests and delete them. */
2759 static void
2760 rest_of_handle_null_pointer (tree decl, rtx insns)
2762 open_dump_file (DFI_null, decl);
2763 if (rtl_dump_file)
2764 dump_flow_info (rtl_dump_file);
2766 if (delete_null_pointer_checks (insns))
2767 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2769 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2772 /* Try combining insns through substitution. */
2773 static void
2774 rest_of_handle_combine (tree decl, rtx insns)
2776 int rebuild_jump_labels_after_combine = 0;
2778 timevar_push (TV_COMBINE);
2779 open_dump_file (DFI_combine, decl);
2781 rebuild_jump_labels_after_combine
2782 = combine_instructions (insns, max_reg_num ());
2784 /* Combining insns may have turned an indirect jump into a
2785 direct jump. Rebuild the JUMP_LABEL fields of jumping
2786 instructions. */
2787 if (rebuild_jump_labels_after_combine)
2789 timevar_push (TV_JUMP);
2790 rebuild_jump_labels (insns);
2791 timevar_pop (TV_JUMP);
2793 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2796 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2797 timevar_pop (TV_COMBINE);
2799 ggc_collect ();
2802 /* Perform life analysis. */
2803 static void
2804 rest_of_handle_life (tree decl, rtx insns)
2806 open_dump_file (DFI_life, decl);
2807 regclass_init ();
2809 #ifdef ENABLE_CHECKING
2810 verify_flow_info ();
2811 #endif
2812 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2813 if (optimize)
2814 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2815 | CLEANUP_LOG_LINKS
2816 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2817 timevar_pop (TV_FLOW);
2819 if (warn_uninitialized)
2821 uninitialized_vars_warning (DECL_INITIAL (decl));
2822 if (extra_warnings)
2823 setjmp_args_warning ();
2826 if (optimize)
2828 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2830 /* Insns were inserted, and possibly pseudos created, so
2831 things might look a bit different. */
2832 insns = get_insns ();
2833 allocate_reg_life_data ();
2834 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2835 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2839 no_new_pseudos = 1;
2841 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2843 ggc_collect ();
2846 /* Perform common subexpression elimination. Nonzero value from
2847 `cse_main' means that jumps were simplified and some code may now
2848 be unreachable, so do jump optimization again. */
2849 static void
2850 rest_of_handle_cse (tree decl, rtx insns)
2852 int tem;
2854 open_dump_file (DFI_cse, decl);
2855 if (rtl_dump_file)
2856 dump_flow_info (rtl_dump_file);
2857 timevar_push (TV_CSE);
2859 reg_scan (insns, max_reg_num (), 1);
2861 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2862 if (tem)
2863 rebuild_jump_labels (insns);
2864 if (purge_all_dead_edges (0))
2865 delete_unreachable_blocks ();
2867 delete_trivially_dead_insns (insns, max_reg_num ());
2869 /* If we are not running more CSE passes, then we are no longer
2870 expecting CSE to be run. But always rerun it in a cheap mode. */
2871 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2873 if (tem || optimize > 1)
2874 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2875 /* Try to identify useless null pointer tests and delete them. */
2876 if (flag_delete_null_pointer_checks)
2878 timevar_push (TV_JUMP);
2880 if (delete_null_pointer_checks (insns))
2881 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2882 timevar_pop (TV_JUMP);
2885 /* The second pass of jump optimization is likely to have
2886 removed a bunch more instructions. */
2887 renumber_insns (rtl_dump_file);
2889 timevar_pop (TV_CSE);
2890 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2893 /* Run second CSE pass after loop optimizations. */
2894 static void
2895 rest_of_handle_cse2 (tree decl, rtx insns)
2897 int tem;
2899 timevar_push (TV_CSE2);
2900 open_dump_file (DFI_cse2, decl);
2901 if (rtl_dump_file)
2902 dump_flow_info (rtl_dump_file);
2903 /* CFG is no longer maintained up-to-date. */
2904 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2906 /* Run a pass to eliminate duplicated assignments to condition code
2907 registers. We have to run this after bypass_jumps, because it
2908 makes it harder for that pass to determine whether a jump can be
2909 bypassed safely. */
2910 cse_condition_code_reg ();
2912 purge_all_dead_edges (0);
2913 delete_trivially_dead_insns (insns, max_reg_num ());
2915 if (tem)
2917 timevar_push (TV_JUMP);
2918 rebuild_jump_labels (insns);
2919 cleanup_cfg (CLEANUP_EXPENSIVE);
2920 timevar_pop (TV_JUMP);
2922 reg_scan (insns, max_reg_num (), 0);
2923 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2924 ggc_collect ();
2925 timevar_pop (TV_CSE2);
2928 /* Perform global cse. */
2929 static void
2930 rest_of_handle_gcse (tree decl, rtx insns)
2932 int save_csb, save_cfj;
2933 int tem2 = 0, tem;
2935 timevar_push (TV_GCSE);
2936 open_dump_file (DFI_gcse, decl);
2938 tem = gcse_main (insns, rtl_dump_file);
2939 rebuild_jump_labels (insns);
2940 delete_trivially_dead_insns (insns, max_reg_num ());
2942 save_csb = flag_cse_skip_blocks;
2943 save_cfj = flag_cse_follow_jumps;
2944 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2946 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2947 if (current_function_calls_constant_p)
2948 purge_builtin_constant_p ();
2950 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2951 by gcse. */
2952 if (flag_expensive_optimizations)
2954 timevar_push (TV_CSE);
2955 reg_scan (insns, max_reg_num (), 1);
2956 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2957 purge_all_dead_edges (0);
2958 delete_trivially_dead_insns (insns, max_reg_num ());
2959 timevar_pop (TV_CSE);
2960 cse_not_expected = !flag_rerun_cse_after_loop;
2963 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2964 things up. Then possibly re-run CSE again. */
2965 while (tem || tem2)
2967 tem = tem2 = 0;
2968 timevar_push (TV_JUMP);
2969 rebuild_jump_labels (insns);
2970 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2971 timevar_pop (TV_JUMP);
2973 if (flag_expensive_optimizations)
2975 timevar_push (TV_CSE);
2976 reg_scan (insns, max_reg_num (), 1);
2977 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2978 purge_all_dead_edges (0);
2979 delete_trivially_dead_insns (insns, max_reg_num ());
2980 timevar_pop (TV_CSE);
2984 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2985 timevar_pop (TV_GCSE);
2987 ggc_collect ();
2988 flag_cse_skip_blocks = save_csb;
2989 flag_cse_follow_jumps = save_cfj;
2990 #ifdef ENABLE_CHECKING
2991 verify_flow_info ();
2992 #endif
2995 /* Move constant computations out of loops. */
2996 static void
2997 rest_of_handle_loop_optimize (tree decl, rtx insns)
2999 int do_unroll, do_prefetch;
3001 timevar_push (TV_LOOP);
3002 delete_dead_jumptables ();
3003 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3004 open_dump_file (DFI_loop, decl);
3006 /* CFG is no longer maintained up-to-date. */
3007 free_bb_for_insn ();
3009 if (flag_unroll_loops)
3010 do_unroll = LOOP_AUTO_UNROLL; /* Having two unrollers is useless. */
3011 else
3012 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
3013 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
3015 if (flag_rerun_loop_opt)
3017 cleanup_barriers ();
3019 /* We only want to perform unrolling once. */
3020 loop_optimize (insns, rtl_dump_file, do_unroll);
3021 do_unroll = 0;
3023 /* The first call to loop_optimize makes some instructions
3024 trivially dead. We delete those instructions now in the
3025 hope that doing so will make the heuristics in loop work
3026 better and possibly speed up compilation. */
3027 delete_trivially_dead_insns (insns, max_reg_num ());
3029 /* The regscan pass is currently necessary as the alias
3030 analysis code depends on this information. */
3031 reg_scan (insns, max_reg_num (), 1);
3033 cleanup_barriers ();
3034 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3036 /* Loop can create trivially dead instructions. */
3037 delete_trivially_dead_insns (insns, max_reg_num ());
3038 close_dump_file (DFI_loop, print_rtl, insns);
3039 timevar_pop (TV_LOOP);
3040 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3042 ggc_collect ();
3045 /* Perform loop optimizations. It might be better to do them a bit
3046 sooner, but we want the profile feedback to work more
3047 efficiently. */
3048 static void
3049 rest_of_handle_loop2 (tree decl, rtx insns)
3051 struct loops *loops;
3052 timevar_push (TV_LOOP);
3053 open_dump_file (DFI_loop2, decl);
3054 if (rtl_dump_file)
3055 dump_flow_info (rtl_dump_file);
3057 loops = loop_optimizer_init (rtl_dump_file);
3059 if (loops)
3061 /* The optimizations: */
3062 if (flag_unswitch_loops)
3063 unswitch_loops (loops);
3065 if (flag_peel_loops || flag_unroll_loops)
3066 unroll_and_peel_loops (loops,
3067 (flag_peel_loops ? UAP_PEEL : 0) |
3068 (flag_unroll_loops ? UAP_UNROLL : 0) |
3069 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3071 loop_optimizer_finalize (loops, rtl_dump_file);
3074 cleanup_cfg (CLEANUP_EXPENSIVE);
3075 delete_trivially_dead_insns (insns, max_reg_num ());
3076 reg_scan (insns, max_reg_num (), 0);
3077 if (rtl_dump_file)
3078 dump_flow_info (rtl_dump_file);
3079 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3080 timevar_pop (TV_LOOP);
3081 ggc_collect ();
3084 /* This is called from finish_function (within langhooks.parse_file)
3085 after each top-level definition is parsed.
3086 It is supposed to compile that function or variable
3087 and output the assembler code for it.
3088 After we return, the tree storage is freed. */
3090 void
3091 rest_of_compilation (tree decl)
3093 rtx insns;
3095 timevar_push (TV_REST_OF_COMPILATION);
3097 /* Register rtl specific functions for cfg. */
3098 rtl_register_cfg_hooks ();
3100 /* Now that we're out of the frontend, we shouldn't have any more
3101 CONCATs anywhere. */
3102 generating_concat_p = 0;
3104 /* When processing delayed functions, prepare_function_start() won't
3105 have been run to re-initialize it. */
3106 cse_not_expected = ! optimize;
3108 /* First, make sure that NOTE_BLOCK is set correctly for each
3109 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3110 if (!cfun->x_whole_function_mode_p)
3111 identify_blocks ();
3113 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3114 tree in sensible shape. So, we just recalculate it here. */
3115 if (cfun->x_whole_function_mode_p)
3116 reorder_blocks ();
3118 init_flow ();
3120 if (rest_of_handle_inlining (decl))
3121 goto exit_rest_of_compilation;
3123 /* If we're emitting a nested function, make sure its parent gets
3124 emitted as well. Doing otherwise confuses debug info. */
3126 tree parent;
3127 for (parent = DECL_CONTEXT (current_function_decl);
3128 parent != NULL_TREE;
3129 parent = get_containing_scope (parent))
3130 if (TREE_CODE (parent) == FUNCTION_DECL)
3131 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3134 /* We are now committed to emitting code for this function. Do any
3135 preparation, such as emitting abstract debug info for the inline
3136 before it gets mangled by optimization. */
3137 if (cgraph_function_possibly_inlined_p (decl))
3138 (*debug_hooks->outlining_inline_function) (decl);
3140 /* Remove any notes we don't need. That will make iterating
3141 over the instruction sequence faster, and allow the garbage
3142 collector to reclaim the memory used by the notes. */
3143 remove_unnecessary_notes ();
3144 reorder_blocks ();
3146 ggc_collect ();
3148 /* Initialize some variables used by the optimizers. */
3149 init_function_for_compilation ();
3151 if (! DECL_DEFER_OUTPUT (decl))
3152 TREE_ASM_WRITTEN (decl) = 1;
3154 /* Now that integrate will no longer see our rtl, we need not
3155 distinguish between the return value of this function and the
3156 return value of called functions. Also, we can remove all SETs
3157 of subregs of hard registers; they are only here because of
3158 integrate. Also, we can now initialize pseudos intended to
3159 carry magic hard reg data throughout the function. */
3160 rtx_equal_function_value_matters = 0;
3161 purge_hard_subreg_sets (get_insns ());
3163 /* Early return if there were errors. We can run afoul of our
3164 consistency checks, and there's not really much point in fixing them.
3165 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3166 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3167 || errorcount || sorrycount)
3168 goto exit_rest_of_compilation;
3170 timevar_push (TV_JUMP);
3171 open_dump_file (DFI_sibling, decl);
3172 insns = get_insns ();
3173 rebuild_jump_labels (insns);
3174 find_exception_handler_labels ();
3175 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3177 delete_unreachable_blocks ();
3179 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3180 if (flag_guess_branch_prob)
3182 timevar_push (TV_BRANCH_PROB);
3183 note_prediction_to_br_prob ();
3184 timevar_pop (TV_BRANCH_PROB);
3187 if (flag_optimize_sibling_calls)
3188 rest_of_handle_sibling_calls (insns);
3190 /* We have to issue these warnings now already, because CFG cleanups
3191 further down may destroy the required information. However, this
3192 must be done after the sibcall optimization pass because the barrier
3193 emitted for noreturn calls that are candidate for the optimization
3194 is folded into the CALL_PLACEHOLDER until after this pass, so the
3195 CFG is inaccurate. */
3196 check_function_return_warnings ();
3198 timevar_pop (TV_JUMP);
3200 insn_locators_initialize ();
3201 /* Complete generation of exception handling code. */
3202 if (doing_eh (0))
3204 timevar_push (TV_JUMP);
3205 open_dump_file (DFI_eh, decl);
3207 finish_eh_generation ();
3209 close_dump_file (DFI_eh, print_rtl, get_insns ());
3210 timevar_pop (TV_JUMP);
3213 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3214 generation, which might create new sets. */
3215 emit_initial_value_sets ();
3217 #ifdef FINALIZE_PIC
3218 /* If we are doing position-independent code generation, now
3219 is the time to output special prologues and epilogues.
3220 We do not want to do this earlier, because it just clutters
3221 up inline functions with meaningless insns. */
3222 if (flag_pic)
3223 FINALIZE_PIC;
3224 #endif
3226 insns = get_insns ();
3228 /* Copy any shared structure that should not be shared. */
3229 unshare_all_rtl (current_function_decl, insns);
3231 #ifdef SETJMP_VIA_SAVE_AREA
3232 /* This must be performed before virtual register instantiation.
3233 Please be aware the everything in the compiler that can look
3234 at the RTL up to this point must understand that REG_SAVE_AREA
3235 is just like a use of the REG contained inside. */
3236 if (current_function_calls_alloca)
3237 optimize_save_area_alloca (insns);
3238 #endif
3240 /* Instantiate all virtual registers. */
3241 instantiate_virtual_regs (current_function_decl, insns);
3243 open_dump_file (DFI_jump, decl);
3245 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3246 are initialized and to compute whether control can drop off the end
3247 of the function. */
3249 timevar_push (TV_JUMP);
3250 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3251 before jump optimization switches branch directions. */
3252 if (flag_guess_branch_prob)
3253 expected_value_to_br_prob ();
3255 reg_scan (insns, max_reg_num (), 0);
3256 rebuild_jump_labels (insns);
3257 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3258 delete_trivially_dead_insns (insns, max_reg_num ());
3259 if (rtl_dump_file)
3260 dump_flow_info (rtl_dump_file);
3261 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3262 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3264 if (optimize)
3266 free_bb_for_insn ();
3267 copy_loop_headers (insns);
3268 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3270 purge_line_number_notes (insns);
3272 timevar_pop (TV_JUMP);
3273 close_dump_file (DFI_jump, print_rtl, insns);
3275 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3276 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3277 goto exit_rest_of_compilation;
3279 timevar_push (TV_JUMP);
3281 if (optimize)
3282 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3284 if (flag_delete_null_pointer_checks)
3285 rest_of_handle_null_pointer (decl, insns);
3287 /* Jump optimization, and the removal of NULL pointer checks, may
3288 have reduced the number of instructions substantially. CSE, and
3289 future passes, allocate arrays whose dimensions involve the
3290 maximum instruction UID, so if we can reduce the maximum UID
3291 we'll save big on memory. */
3292 renumber_insns (rtl_dump_file);
3293 timevar_pop (TV_JUMP);
3295 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3297 ggc_collect ();
3299 if (optimize > 0)
3300 rest_of_handle_cse (decl, insns);
3302 rest_of_handle_addressof (decl, insns);
3304 ggc_collect ();
3306 if (optimize > 0)
3308 if (flag_gcse)
3309 rest_of_handle_gcse (decl, insns);
3311 if (flag_loop_optimize)
3312 rest_of_handle_loop_optimize (decl, insns);
3315 timevar_push (TV_FLOW);
3317 rest_of_handle_cfg (decl, insns);
3319 if (optimize > 0
3320 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3322 rest_of_handle_branch_prob (decl, insns);
3324 if (flag_branch_probabilities
3325 && flag_profile_values
3326 && flag_value_profile_transformations)
3327 rest_of_handle_value_profile_transformations (decl, insns);
3329 /* Remove the death notes created for vpt. */
3330 if (flag_profile_values)
3331 count_or_remove_death_notes (NULL, 1);
3334 if (optimize > 0)
3335 rest_of_handle_if_conversion (decl, insns);
3337 if (flag_tracer)
3338 rest_of_handle_tracer (decl, insns);
3340 if (optimize > 0)
3342 if (flag_unswitch_loops
3343 || flag_peel_loops
3344 || flag_unroll_loops)
3345 rest_of_handle_loop2 (decl, insns);
3347 if (flag_gcse)
3348 rest_of_handle_jump_bypass (decl, insns);
3351 if (flag_web)
3352 rest_of_handle_web (decl, insns);
3354 if (flag_rerun_cse_after_loop)
3355 rest_of_handle_cse2 (decl, insns);
3357 cse_not_expected = 1;
3359 rest_of_handle_life (decl, insns);
3361 if (optimize > 0)
3362 rest_of_handle_combine (decl, insns);
3364 if (flag_if_conversion)
3365 rest_of_handle_if_after_combine (decl, insns);
3367 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3368 rest_of_handle_regmove (decl, insns);
3370 /* Do unconditional splitting before register allocation to allow machine
3371 description to add extra information not needed previously. */
3372 split_all_insns (1);
3374 #ifdef OPTIMIZE_MODE_SWITCHING
3375 timevar_push (TV_MODE_SWITCH);
3377 no_new_pseudos = 0;
3378 optimize_mode_switching (NULL);
3379 no_new_pseudos = 1;
3381 timevar_pop (TV_MODE_SWITCH);
3382 #endif
3384 /* Any of the several passes since flow1 will have munged register
3385 lifetime data a bit. We need it to be up to date for scheduling
3386 (see handling of reg_known_equiv in init_alias_analysis). */
3387 recompute_reg_usage (insns, !optimize_size);
3389 #ifdef INSN_SCHEDULING
3390 rest_of_handle_sched (decl, insns);
3391 #endif
3393 /* Determine if the current function is a leaf before running reload
3394 since this can impact optimizations done by the prologue and
3395 epilogue thus changing register elimination offsets. */
3396 current_function_is_leaf = leaf_function_p ();
3398 timevar_push (TV_LOCAL_ALLOC);
3399 open_dump_file (DFI_lreg, decl);
3401 if (flag_new_regalloc)
3403 if (rest_of_handle_new_regalloc (decl, insns))
3404 goto exit_rest_of_compilation;
3406 else
3408 if (rest_of_handle_old_regalloc (decl, insns))
3409 goto exit_rest_of_compilation;
3412 ggc_collect ();
3414 open_dump_file (DFI_postreload, decl);
3416 /* Do a very simple CSE pass over just the hard registers. */
3417 if (optimize > 0)
3419 timevar_push (TV_RELOAD_CSE_REGS);
3420 reload_cse_regs (insns);
3421 /* reload_cse_regs can eliminate potentially-trapping MEMs.
3422 Remove any EH edges associated with them. */
3423 if (flag_non_call_exceptions)
3424 purge_all_dead_edges (0);
3425 timevar_pop (TV_RELOAD_CSE_REGS);
3428 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3430 /* Re-create the death notes which were deleted during reload. */
3431 timevar_push (TV_FLOW2);
3432 open_dump_file (DFI_flow2, decl);
3434 #ifdef ENABLE_CHECKING
3435 verify_flow_info ();
3436 #endif
3438 /* If optimizing, then go ahead and split insns now. */
3439 #ifndef STACK_REGS
3440 if (optimize > 0)
3441 #endif
3442 split_all_insns (0);
3444 if (flag_branch_target_load_optimize)
3446 open_dump_file (DFI_branch_target_load, decl);
3448 branch_target_load_optimize (insns, false);
3450 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3452 ggc_collect ();
3455 if (optimize)
3456 cleanup_cfg (CLEANUP_EXPENSIVE);
3458 /* On some machines, the prologue and epilogue code, or parts thereof,
3459 can be represented as RTL. Doing so lets us schedule insns between
3460 it and the rest of the code and also allows delayed branch
3461 scheduling to operate in the epilogue. */
3462 thread_prologue_and_epilogue_insns (insns);
3463 epilogue_completed = 1;
3465 if (optimize)
3467 life_analysis (insns, rtl_dump_file, PROP_POSTRELOAD);
3468 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3469 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3471 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3472 even for machines with possibly nonzero RETURN_POPS_ARGS
3473 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3474 push instructions will have popping returns. */
3475 #ifndef PUSH_ROUNDING
3476 if (!ACCUMULATE_OUTGOING_ARGS)
3477 #endif
3478 combine_stack_adjustments ();
3480 ggc_collect ();
3483 flow2_completed = 1;
3485 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3486 timevar_pop (TV_FLOW2);
3488 #ifdef HAVE_peephole2
3489 if (optimize > 0 && flag_peephole2)
3491 timevar_push (TV_PEEPHOLE2);
3492 open_dump_file (DFI_peephole2, decl);
3494 peephole2_optimize (rtl_dump_file);
3496 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3497 timevar_pop (TV_PEEPHOLE2);
3499 #endif
3501 open_dump_file (DFI_ce3, decl);
3502 if (optimize)
3503 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
3504 splitting possibly introduced more crossjumping opportunities. */
3505 cleanup_cfg (CLEANUP_EXPENSIVE
3506 | CLEANUP_UPDATE_LIFE
3507 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3508 if (flag_if_conversion2)
3510 timevar_push (TV_IFCVT2);
3512 if_convert (1);
3514 timevar_pop (TV_IFCVT2);
3516 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3518 if (optimize > 0)
3520 if (flag_rename_registers || flag_cprop_registers)
3521 rest_of_handle_regrename (decl, insns);
3523 rest_of_handle_reorder_blocks (decl, insns);
3526 if (flag_branch_target_load_optimize2)
3528 /* Leave this a warning for now so that it is possible to experiment
3529 with running this pass twice. In 3.6, we should either make this
3530 an error, or use separate dump files. */
3531 if (flag_branch_target_load_optimize)
3532 warning ("branch target register load optimization is not intended "
3533 "to be run twice");
3535 open_dump_file (DFI_branch_target_load, decl);
3537 branch_target_load_optimize (insns, true);
3539 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3541 ggc_collect ();
3544 #ifdef INSN_SCHEDULING
3545 if (optimize > 0 && flag_schedule_insns_after_reload)
3546 rest_of_handle_sched2 (decl, insns);
3547 #endif
3549 #ifdef LEAF_REGISTERS
3550 current_function_uses_only_leaf_regs
3551 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3552 #endif
3554 #ifdef STACK_REGS
3555 rest_of_handle_stack_regs (decl, insns);
3556 #endif
3558 compute_alignments ();
3560 /* CFG is no longer maintained up-to-date. */
3561 free_bb_for_insn ();
3563 if (targetm.machine_dependent_reorg != 0)
3564 rest_of_handle_machine_reorg (decl, insns);
3566 purge_line_number_notes (insns);
3567 cleanup_barriers ();
3569 #ifdef DELAY_SLOTS
3570 if (optimize > 0 && flag_delayed_branch)
3571 rest_of_handle_delay_slots (decl, insns);
3572 #endif
3574 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3575 timevar_push (TV_SHORTEN_BRANCH);
3576 split_all_insns_noflow ();
3577 timevar_pop (TV_SHORTEN_BRANCH);
3578 #endif
3580 convert_to_eh_region_ranges ();
3582 /* Shorten branches. */
3583 timevar_push (TV_SHORTEN_BRANCH);
3584 shorten_branches (get_insns ());
3585 timevar_pop (TV_SHORTEN_BRANCH);
3587 set_nothrow_function_flags ();
3588 if (current_function_nothrow)
3589 /* Now we know that this can't throw; set the flag for the benefit
3590 of other functions later in this translation unit. */
3591 TREE_NOTHROW (current_function_decl) = 1;
3593 rest_of_handle_final (decl, insns);
3595 /* Write DBX symbols if requested. */
3597 /* Note that for those inline functions where we don't initially
3598 know for certain that we will be generating an out-of-line copy,
3599 the first invocation of this routine (rest_of_compilation) will
3600 skip over this code by doing a `goto exit_rest_of_compilation;'.
3601 Later on, wrapup_global_declarations will (indirectly) call
3602 rest_of_compilation again for those inline functions that need
3603 to have out-of-line copies generated. During that call, we
3604 *will* be routed past here. */
3606 timevar_push (TV_SYMOUT);
3607 (*debug_hooks->function_decl) (decl);
3608 timevar_pop (TV_SYMOUT);
3610 exit_rest_of_compilation:
3612 coverage_end_function ();
3614 /* In case the function was not output,
3615 don't leave any temporary anonymous types
3616 queued up for sdb output. */
3617 #ifdef SDB_DEBUGGING_INFO
3618 if (write_symbols == SDB_DEBUG)
3619 sdbout_types (NULL_TREE);
3620 #endif
3622 reload_completed = 0;
3623 epilogue_completed = 0;
3624 flow2_completed = 0;
3625 no_new_pseudos = 0;
3627 timevar_push (TV_FINAL);
3629 /* Clear out the insn_length contents now that they are no
3630 longer valid. */
3631 init_insn_lengths ();
3633 /* Show no temporary slots allocated. */
3634 init_temp_slots ();
3636 free_basic_block_vars (0);
3637 free_bb_for_insn ();
3639 timevar_pop (TV_FINAL);
3641 if ((*targetm.binds_local_p) (current_function_decl))
3643 int pref = cfun->preferred_stack_boundary;
3644 if (cfun->recursive_call_emit
3645 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3646 pref = cfun->stack_alignment_needed;
3647 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3648 = pref;
3651 /* Make sure volatile mem refs aren't considered valid operands for
3652 arithmetic insns. We must call this here if this is a nested inline
3653 function, since the above code leaves us in the init_recog state
3654 (from final.c), and the function context push/pop code does not
3655 save/restore volatile_ok.
3657 ??? Maybe it isn't necessary for expand_start_function to call this
3658 anymore if we do it here? */
3660 init_recog_no_volatile ();
3662 /* We're done with this function. Free up memory if we can. */
3663 free_after_parsing (cfun);
3664 if (! DECL_DEFER_OUTPUT (decl))
3666 free_after_compilation (cfun);
3667 DECL_SAVED_INSNS (decl) = 0;
3669 cfun = 0;
3671 ggc_collect ();
3673 timevar_pop (TV_REST_OF_COMPILATION);
3676 /* Display help for target options. */
3677 void
3678 display_target_options (void)
3680 int undoc, i;
3681 static bool displayed = false;
3683 /* Avoid double printing for --help --target-help. */
3684 if (displayed)
3685 return;
3687 displayed = true;
3689 if (ARRAY_SIZE (target_switches) > 1
3690 #ifdef TARGET_OPTIONS
3691 || ARRAY_SIZE (target_options) > 1
3692 #endif
3695 int doc = 0;
3697 undoc = 0;
3699 printf (_("\nTarget specific options:\n"));
3701 for (i = ARRAY_SIZE (target_switches); i--;)
3703 const char *option = target_switches[i].name;
3704 const char *description = target_switches[i].description;
3706 if (option == NULL || *option == 0)
3707 continue;
3708 else if (description == NULL)
3710 undoc = 1;
3712 if (extra_warnings)
3713 printf (_(" -m%-23s [undocumented]\n"), option);
3715 else if (*description != 0)
3716 doc += printf (" -m%-23s %s\n", option, _(description));
3719 #ifdef TARGET_OPTIONS
3720 for (i = ARRAY_SIZE (target_options); i--;)
3722 const char *option = target_options[i].prefix;
3723 const char *description = target_options[i].description;
3725 if (option == NULL || *option == 0)
3726 continue;
3727 else if (description == NULL)
3729 undoc = 1;
3731 if (extra_warnings)
3732 printf (_(" -m%-23s [undocumented]\n"), option);
3734 else if (*description != 0)
3735 doc += printf (" -m%-23s %s\n", option, _(description));
3737 #endif
3738 if (undoc)
3740 if (doc)
3741 printf (_("\nThere are undocumented target specific options as well.\n"));
3742 else
3743 printf (_(" They exist, but they are not documented.\n"));
3748 /* Parse a -d... command line switch. */
3750 void
3751 decode_d_option (const char *arg)
3753 int i, c, matched;
3755 while (*arg)
3756 switch (c = *arg++)
3758 case 'a':
3759 for (i = 0; i < (int) DFI_MAX; ++i)
3760 dump_file[i].enabled = 1;
3761 break;
3762 case 'A':
3763 flag_debug_asm = 1;
3764 break;
3765 case 'p':
3766 flag_print_asm_name = 1;
3767 break;
3768 case 'P':
3769 flag_dump_rtl_in_asm = 1;
3770 flag_print_asm_name = 1;
3771 break;
3772 case 'v':
3773 graph_dump_format = vcg;
3774 break;
3775 case 'x':
3776 rtl_dump_and_exit = 1;
3777 break;
3778 case 'y':
3779 set_yydebug = 1;
3780 break;
3781 case 'D': /* These are handled by the preprocessor. */
3782 case 'I':
3783 break;
3784 case 'H':
3785 setup_core_dumping();
3786 break;
3788 default:
3789 matched = 0;
3790 for (i = 0; i < (int) DFI_MAX; ++i)
3791 if (c == dump_file[i].debug_switch)
3793 dump_file[i].enabled = 1;
3794 matched = 1;
3797 if (! matched)
3798 warning ("unrecognized gcc debugging option: %c", c);
3799 break;
3803 /* Indexed by enum debug_info_type. */
3804 const char *const debug_type_names[] =
3806 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3809 /* Decode -m switches. */
3810 /* Decode the switch -mNAME. */
3812 void
3813 set_target_switch (const char *name)
3815 size_t j;
3816 int valid_target_option = 0;
3818 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3819 if (!strcmp (target_switches[j].name, name))
3821 if (target_switches[j].value < 0)
3822 target_flags &= ~-target_switches[j].value;
3823 else
3824 target_flags |= target_switches[j].value;
3825 if (name[0] != 0)
3827 if (target_switches[j].value < 0)
3828 target_flags_explicit |= -target_switches[j].value;
3829 else
3830 target_flags_explicit |= target_switches[j].value;
3832 valid_target_option = 1;
3835 #ifdef TARGET_OPTIONS
3836 if (!valid_target_option)
3837 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3839 int len = strlen (target_options[j].prefix);
3840 if (target_options[j].value)
3842 if (!strcmp (target_options[j].prefix, name))
3844 *target_options[j].variable = target_options[j].value;
3845 valid_target_option = 1;
3848 else
3850 if (!strncmp (target_options[j].prefix, name, len))
3852 *target_options[j].variable = name + len;
3853 valid_target_option = 1;
3857 #endif
3859 if (!valid_target_option)
3860 error ("invalid option `%s'", name);
3863 /* Print version information to FILE.
3864 Each line begins with INDENT (for the case where FILE is the
3865 assembler output file). */
3867 void
3868 print_version (FILE *file, const char *indent)
3870 #ifndef __VERSION__
3871 #define __VERSION__ "[?]"
3872 #endif
3873 fnotice (file,
3874 #ifdef __GNUC__
3875 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3876 #else
3877 "%s%s%s version %s (%s) compiled by CC.\n"
3878 #endif
3879 , indent, *indent != 0 ? " " : "",
3880 lang_hooks.name, version_string, TARGET_NAME,
3881 indent, __VERSION__);
3882 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3883 indent, *indent != 0 ? " " : "",
3884 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3887 /* Print an option value and return the adjusted position in the line.
3888 ??? We don't handle error returns from fprintf (disk full); presumably
3889 other code will catch a disk full though. */
3891 static int
3892 print_single_switch (FILE *file, int pos, int max,
3893 const char *indent, const char *sep, const char *term,
3894 const char *type, const char *name)
3896 /* The ultrix fprintf returns 0 on success, so compute the result we want
3897 here since we need it for the following test. */
3898 int len = strlen (sep) + strlen (type) + strlen (name);
3900 if (pos != 0
3901 && pos + len > max)
3903 fprintf (file, "%s", term);
3904 pos = 0;
3906 if (pos == 0)
3908 fprintf (file, "%s", indent);
3909 pos = strlen (indent);
3911 fprintf (file, "%s%s%s", sep, type, name);
3912 pos += len;
3913 return pos;
3916 /* Print active target switches to FILE.
3917 POS is the current cursor position and MAX is the size of a "line".
3918 Each line begins with INDENT and ends with TERM.
3919 Each switch is separated from the next by SEP. */
3921 static void
3922 print_switch_values (FILE *file, int pos, int max,
3923 const char *indent, const char *sep, const char *term)
3925 size_t j;
3926 const char **p;
3928 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3929 that it can be printed below. This helps reproducibility. */
3930 randomize ();
3932 /* Print the options as passed. */
3933 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3934 _("options passed: "), "");
3936 for (p = &save_argv[1]; *p != NULL; p++)
3937 if (**p == '-')
3939 /* Ignore these. */
3940 if (strcmp (*p, "-o") == 0)
3942 if (p[1] != NULL)
3943 p++;
3944 continue;
3946 if (strcmp (*p, "-quiet") == 0)
3947 continue;
3948 if (strcmp (*p, "-version") == 0)
3949 continue;
3950 if ((*p)[1] == 'd')
3951 continue;
3953 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
3955 if (pos > 0)
3956 fprintf (file, "%s", term);
3958 /* Print the -f and -m options that have been enabled.
3959 We don't handle language specific options but printing argv
3960 should suffice. */
3962 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
3963 _("options enabled: "), "");
3965 for (j = 0; j < ARRAY_SIZE (f_options); j++)
3966 if (*f_options[j].variable == f_options[j].on_value)
3967 pos = print_single_switch (file, pos, max, indent, sep, term,
3968 "-f", f_options[j].string);
3970 /* Print target specific options. */
3972 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3973 if (target_switches[j].name[0] != '\0'
3974 && target_switches[j].value > 0
3975 && ((target_switches[j].value & target_flags)
3976 == target_switches[j].value))
3978 pos = print_single_switch (file, pos, max, indent, sep, term,
3979 "-m", target_switches[j].name);
3982 #ifdef TARGET_OPTIONS
3983 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3984 if (*target_options[j].variable != NULL)
3986 char prefix[256];
3987 sprintf (prefix, "-m%s", target_options[j].prefix);
3988 pos = print_single_switch (file, pos, max, indent, sep, term,
3989 prefix, *target_options[j].variable);
3991 #endif
3993 fprintf (file, "%s", term);
3996 /* Open assembly code output file. Do this even if -fsyntax-only is
3997 on, because then the driver will have provided the name of a
3998 temporary file or bit bucket for us. NAME is the file specified on
3999 the command line, possibly NULL. */
4000 static void
4001 init_asm_output (const char *name)
4003 if (name == NULL && asm_file_name == 0)
4004 asm_out_file = stdout;
4005 else
4007 if (asm_file_name == 0)
4009 int len = strlen (dump_base_name);
4010 char *dumpname = xmalloc (len + 6);
4011 memcpy (dumpname, dump_base_name, len + 1);
4012 strip_off_ending (dumpname, len);
4013 strcat (dumpname, ".s");
4014 asm_file_name = dumpname;
4016 if (!strcmp (asm_file_name, "-"))
4017 asm_out_file = stdout;
4018 else
4019 asm_out_file = fopen (asm_file_name, "w+");
4020 if (asm_out_file == 0)
4021 fatal_error ("can't open %s for writing: %m", asm_file_name);
4024 #ifdef IO_BUFFER_SIZE
4025 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
4026 _IOFBF, IO_BUFFER_SIZE);
4027 #endif
4029 if (!flag_syntax_only)
4031 targetm.asm_out.file_start ();
4033 #ifdef ASM_COMMENT_START
4034 if (flag_verbose_asm)
4036 /* Print the list of options in effect. */
4037 print_version (asm_out_file, ASM_COMMENT_START);
4038 print_switch_values (asm_out_file, 0, MAX_LINE,
4039 ASM_COMMENT_START, " ", "\n");
4040 /* Add a blank line here so it appears in assembler output but not
4041 screen output. */
4042 fprintf (asm_out_file, "\n");
4044 #endif
4048 /* Default version of get_pch_validity.
4049 By default, every flag difference is fatal; that will be mostly right for
4050 most targets, but completely right for very few. */
4052 void *
4053 default_get_pch_validity (size_t *len)
4055 #ifdef TARGET_OPTIONS
4056 size_t i;
4057 #endif
4058 char *result, *r;
4060 *len = sizeof (target_flags) + 2;
4061 #ifdef TARGET_OPTIONS
4062 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4064 *len += 1;
4065 if (*target_options[i].variable)
4066 *len += strlen (*target_options[i].variable);
4068 #endif
4070 result = r = xmalloc (*len);
4071 r[0] = flag_pic;
4072 r[1] = flag_pie;
4073 r += 2;
4074 memcpy (r, &target_flags, sizeof (target_flags));
4075 r += sizeof (target_flags);
4077 #ifdef TARGET_OPTIONS
4078 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4080 const char *str = *target_options[i].variable;
4081 size_t l;
4082 if (! str)
4083 str = "";
4084 l = strlen (str) + 1;
4085 memcpy (r, str, l);
4086 r += l;
4088 #endif
4090 return result;
4093 /* Default version of pch_valid_p. */
4095 const char *
4096 default_pch_valid_p (const void *data_p, size_t len)
4098 const char *data = (const char *)data_p;
4099 const char *flag_that_differs = NULL;
4100 size_t i;
4102 /* -fpic and -fpie also usually make a PCH invalid. */
4103 if (data[0] != flag_pic)
4104 return _("created and used with different settings of -fpic");
4105 if (data[1] != flag_pie)
4106 return _("created and used with different settings of -fpie");
4107 data += 2;
4109 /* Check target_flags. */
4110 if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
4112 for (i = 0; i < ARRAY_SIZE (target_switches); i++)
4114 int bits;
4115 int tf;
4117 memcpy (&tf, data, sizeof (target_flags));
4119 bits = target_switches[i].value;
4120 if (bits < 0)
4121 bits = -bits;
4122 if ((target_flags & bits) != (tf & bits))
4124 flag_that_differs = target_switches[i].name;
4125 goto make_message;
4128 abort ();
4130 data += sizeof (target_flags);
4131 len -= sizeof (target_flags);
4133 /* Check string options. */
4134 #ifdef TARGET_OPTIONS
4135 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4137 const char *str = *target_options[i].variable;
4138 size_t l;
4139 if (! str)
4140 str = "";
4141 l = strlen (str) + 1;
4142 if (len < l || memcmp (data, str, l) != 0)
4144 flag_that_differs = target_options[i].prefix;
4145 goto make_message;
4147 data += l;
4148 len -= l;
4150 #endif
4152 return NULL;
4154 make_message:
4156 char *r;
4157 asprintf (&r, _("created and used with differing settings of `-m%s'"),
4158 flag_that_differs);
4159 if (r == NULL)
4160 return _("out of memory");
4161 return r;
4165 /* Default tree printer. Handles declarations only. */
4166 static bool
4167 default_tree_printer (pretty_printer * pp, text_info *text)
4169 switch (*text->format_spec)
4171 case 'D':
4172 case 'F':
4173 case 'T':
4175 tree t = va_arg (*text->args_ptr, tree);
4176 const char *n = DECL_NAME (t)
4177 ? (*lang_hooks.decl_printable_name) (t, 2)
4178 : "<anonymous>";
4179 pp_string (pp, n);
4181 return true;
4183 default:
4184 return false;
4188 /* Initialization of the front end environment, before command line
4189 options are parsed. Signal handlers, internationalization etc.
4190 ARGV0 is main's argv[0]. */
4191 static void
4192 general_init (const char *argv0)
4194 const char *p;
4196 p = argv0 + strlen (argv0);
4197 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4198 --p;
4199 progname = p;
4201 xmalloc_set_program_name (progname);
4203 hex_init ();
4205 gcc_init_libintl ();
4207 /* Initialize the diagnostics reporting machinery, so option parsing
4208 can give warnings and errors. */
4209 diagnostic_initialize (global_dc);
4210 /* Set a default printer. Language specific initializations will
4211 override it later. */
4212 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4214 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4215 #ifdef SIGSEGV
4216 signal (SIGSEGV, crash_signal);
4217 #endif
4218 #ifdef SIGILL
4219 signal (SIGILL, crash_signal);
4220 #endif
4221 #ifdef SIGBUS
4222 signal (SIGBUS, crash_signal);
4223 #endif
4224 #ifdef SIGABRT
4225 signal (SIGABRT, crash_signal);
4226 #endif
4227 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4228 signal (SIGIOT, crash_signal);
4229 #endif
4230 #ifdef SIGFPE
4231 signal (SIGFPE, crash_signal);
4232 #endif
4234 /* Other host-specific signal setup. */
4235 (*host_hooks.extra_signals)();
4237 /* Initialize the garbage-collector, string pools and tree type hash
4238 table. */
4239 init_ggc ();
4240 init_stringpool ();
4241 linemap_init (&line_table);
4242 init_ttree ();
4244 /* Initialize register usage now so switches may override. */
4245 init_reg_sets ();
4247 /* Register the language-independent parameters. */
4248 add_params (lang_independent_params, LAST_PARAM);
4250 /* This must be done after add_params but before argument processing. */
4251 init_ggc_heuristics();
4254 /* Process the options that have been parsed. */
4255 static void
4256 process_options (void)
4258 /* Allow the front end to perform consistency checks and do further
4259 initialization based on the command line options. This hook also
4260 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4261 so we can correctly initialize debug output. */
4262 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4263 input_filename = main_input_filename;
4265 #ifdef OVERRIDE_OPTIONS
4266 /* Some machines may reject certain combinations of options. */
4267 OVERRIDE_OPTIONS;
4268 #endif
4270 /* Set aux_base_name if not already set. */
4271 if (aux_base_name)
4273 else if (main_input_filename)
4275 char *name = xstrdup (lbasename (main_input_filename));
4277 strip_off_ending (name, strlen (name));
4278 aux_base_name = name;
4280 else
4281 aux_base_name = "gccaux";
4283 /* Set up the align_*_log variables, defaulting them to 1 if they
4284 were still unset. */
4285 if (align_loops <= 0) align_loops = 1;
4286 if (align_loops_max_skip > align_loops || !align_loops)
4287 align_loops_max_skip = align_loops - 1;
4288 align_loops_log = floor_log2 (align_loops * 2 - 1);
4289 if (align_jumps <= 0) align_jumps = 1;
4290 if (align_jumps_max_skip > align_jumps || !align_jumps)
4291 align_jumps_max_skip = align_jumps - 1;
4292 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4293 if (align_labels <= 0) align_labels = 1;
4294 align_labels_log = floor_log2 (align_labels * 2 - 1);
4295 if (align_labels_max_skip > align_labels || !align_labels)
4296 align_labels_max_skip = align_labels - 1;
4297 if (align_functions <= 0) align_functions = 1;
4298 align_functions_log = floor_log2 (align_functions * 2 - 1);
4300 /* Unrolling all loops implies that standard loop unrolling must also
4301 be done. */
4302 if (flag_unroll_all_loops)
4303 flag_unroll_loops = 1;
4305 if (flag_unroll_loops)
4307 flag_old_unroll_loops = 0;
4308 flag_old_unroll_all_loops = 0;
4311 if (flag_old_unroll_all_loops)
4312 flag_old_unroll_loops = 1;
4314 /* Old loop unrolling requires that strength_reduction be on also. Silently
4315 turn on strength reduction here if it isn't already on. Also, the loop
4316 unrolling code assumes that cse will be run after loop, so that must
4317 be turned on also. */
4318 if (flag_old_unroll_loops)
4320 flag_strength_reduce = 1;
4321 flag_rerun_cse_after_loop = 1;
4323 if (flag_unroll_loops || flag_peel_loops)
4324 flag_rerun_cse_after_loop = 1;
4326 if (flag_non_call_exceptions)
4327 flag_asynchronous_unwind_tables = 1;
4328 if (flag_asynchronous_unwind_tables)
4329 flag_unwind_tables = 1;
4331 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4332 interface. */
4333 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4334 flag_unit_at_a_time = 0;
4336 if (flag_value_profile_transformations)
4337 flag_profile_values = 1;
4339 /* Warn about options that are not supported on this machine. */
4340 #ifndef INSN_SCHEDULING
4341 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4342 warning ("instruction scheduling not supported on this target machine");
4343 #endif
4344 #ifndef DELAY_SLOTS
4345 if (flag_delayed_branch)
4346 warning ("this target machine does not have delayed branches");
4347 #endif
4349 user_label_prefix = USER_LABEL_PREFIX;
4350 if (flag_leading_underscore != -1)
4352 /* If the default prefix is more complicated than "" or "_",
4353 issue a warning and ignore this option. */
4354 if (user_label_prefix[0] == 0 ||
4355 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4357 user_label_prefix = flag_leading_underscore ? "_" : "";
4359 else
4360 warning ("-f%sleading-underscore not supported on this target machine",
4361 flag_leading_underscore ? "" : "no-");
4364 /* If we are in verbose mode, write out the version and maybe all the
4365 option flags in use. */
4366 if (version_flag)
4368 print_version (stderr, "");
4369 if (! quiet_flag)
4370 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4373 if (flag_syntax_only)
4375 write_symbols = NO_DEBUG;
4376 profile_flag = 0;
4379 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4380 level is 0. */
4381 if (debug_info_level == DINFO_LEVEL_NONE)
4382 write_symbols = NO_DEBUG;
4384 /* Now we know write_symbols, set up the debug hooks based on it.
4385 By default we do nothing for debug output. */
4386 if (write_symbols == NO_DEBUG)
4387 debug_hooks = &do_nothing_debug_hooks;
4388 #if defined(DBX_DEBUGGING_INFO)
4389 else if (write_symbols == DBX_DEBUG)
4390 debug_hooks = &dbx_debug_hooks;
4391 #endif
4392 #if defined(XCOFF_DEBUGGING_INFO)
4393 else if (write_symbols == XCOFF_DEBUG)
4394 debug_hooks = &xcoff_debug_hooks;
4395 #endif
4396 #ifdef SDB_DEBUGGING_INFO
4397 else if (write_symbols == SDB_DEBUG)
4398 debug_hooks = &sdb_debug_hooks;
4399 #endif
4400 #ifdef DWARF2_DEBUGGING_INFO
4401 else if (write_symbols == DWARF2_DEBUG)
4402 debug_hooks = &dwarf2_debug_hooks;
4403 #endif
4404 #ifdef VMS_DEBUGGING_INFO
4405 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4406 debug_hooks = &vmsdbg_debug_hooks;
4407 #endif
4408 else
4409 error ("target system does not support the \"%s\" debug format",
4410 debug_type_names[write_symbols]);
4412 /* If auxiliary info generation is desired, open the output file.
4413 This goes in the same directory as the source file--unlike
4414 all the other output files. */
4415 if (flag_gen_aux_info)
4417 aux_info_file = fopen (aux_info_file_name, "w");
4418 if (aux_info_file == 0)
4419 fatal_error ("can't open %s: %m", aux_info_file_name);
4422 if (! targetm.have_named_sections)
4424 if (flag_function_sections)
4426 warning ("-ffunction-sections not supported for this target");
4427 flag_function_sections = 0;
4429 if (flag_data_sections)
4431 warning ("-fdata-sections not supported for this target");
4432 flag_data_sections = 0;
4436 if (flag_function_sections && profile_flag)
4438 warning ("-ffunction-sections disabled; it makes profiling impossible");
4439 flag_function_sections = 0;
4442 #ifndef HAVE_prefetch
4443 if (flag_prefetch_loop_arrays)
4445 warning ("-fprefetch-loop-arrays not supported for this target");
4446 flag_prefetch_loop_arrays = 0;
4448 #else
4449 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4451 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4452 flag_prefetch_loop_arrays = 0;
4454 #endif
4456 /* This combination of options isn't handled for i386 targets and doesn't
4457 make much sense anyway, so don't allow it. */
4458 if (flag_prefetch_loop_arrays && optimize_size)
4460 warning ("-fprefetch-loop-arrays is not supported with -Os");
4461 flag_prefetch_loop_arrays = 0;
4464 #ifndef OBJECT_FORMAT_ELF
4465 if (flag_function_sections && write_symbols != NO_DEBUG)
4466 warning ("-ffunction-sections may affect debugging on some targets");
4467 #endif
4469 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4470 if (flag_signaling_nans)
4471 flag_trapping_math = 1;
4474 /* Initialize the compiler back end. */
4475 static void
4476 backend_init (void)
4478 init_adjust_machine_modes ();
4480 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4481 || debug_info_level == DINFO_LEVEL_VERBOSE
4482 #ifdef VMS_DEBUGGING_INFO
4483 /* Enable line number info for traceback. */
4484 || debug_info_level > DINFO_LEVEL_NONE
4485 #endif
4486 || flag_test_coverage
4487 || warn_notreached);
4489 init_regs ();
4490 init_fake_stack_mems ();
4491 init_alias_once ();
4492 init_loop ();
4493 init_reload ();
4494 init_function_once ();
4495 init_varasm_once ();
4497 /* The following initialization functions need to generate rtl, so
4498 provide a dummy function context for them. */
4499 init_dummy_function_start ();
4500 init_expmed ();
4501 if (flag_caller_saves)
4502 init_caller_save ();
4503 expand_dummy_function_end ();
4506 /* Language-dependent initialization. Returns nonzero on success. */
4507 static int
4508 lang_dependent_init (const char *name)
4510 if (dump_base_name == 0)
4511 dump_base_name = name ? name : "gccdump";
4513 /* Other front-end initialization. */
4514 if ((*lang_hooks.init) () == 0)
4515 return 0;
4517 init_asm_output (name);
4519 /* These create various _DECL nodes, so need to be called after the
4520 front end is initialized. */
4521 init_eh ();
4522 init_optabs ();
4524 /* The following initialization functions need to generate rtl, so
4525 provide a dummy function context for them. */
4526 init_dummy_function_start ();
4527 init_expr_once ();
4528 expand_dummy_function_end ();
4530 /* If dbx symbol table desired, initialize writing it and output the
4531 predefined types. */
4532 timevar_push (TV_SYMOUT);
4534 #ifdef DWARF2_UNWIND_INFO
4535 if (dwarf2out_do_frame ())
4536 dwarf2out_frame_init ();
4537 #endif
4539 /* Now we have the correct original filename, we can initialize
4540 debug output. */
4541 (*debug_hooks->init) (name);
4543 timevar_pop (TV_SYMOUT);
4545 return 1;
4548 /* Clean up: close opened files, etc. */
4550 static void
4551 finalize (void)
4553 /* Close the dump files. */
4554 if (flag_gen_aux_info)
4556 fclose (aux_info_file);
4557 if (errorcount)
4558 unlink (aux_info_file_name);
4561 /* Close non-debugging input and output files. Take special care to note
4562 whether fclose returns an error, since the pages might still be on the
4563 buffer chain while the file is open. */
4565 if (asm_out_file)
4567 if (ferror (asm_out_file) != 0)
4568 fatal_error ("error writing to %s: %m", asm_file_name);
4569 if (fclose (asm_out_file) != 0)
4570 fatal_error ("error closing %s: %m", asm_file_name);
4573 /* Do whatever is necessary to finish printing the graphs. */
4574 if (graph_dump_format != no_graph)
4576 int i;
4578 for (i = 0; i < (int) DFI_MAX; ++i)
4579 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4581 char seq[16];
4582 char *suffix;
4584 sprintf (seq, DUMPFILE_FORMAT, i);
4585 suffix = concat (seq, dump_file[i].extension, NULL);
4586 finish_graph_dump_file (dump_base_name, suffix);
4587 free (suffix);
4591 if (mem_report)
4593 ggc_print_statistics ();
4594 stringpool_statistics ();
4595 dump_tree_statistics ();
4596 dump_rtx_statistics ();
4597 dump_varray_statistics ();
4600 /* Free up memory for the benefit of leak detectors. */
4601 free_reg_info ();
4603 /* Language-specific end of compilation actions. */
4604 (*lang_hooks.finish) ();
4607 /* Initialize the compiler, and compile the input file. */
4608 static void
4609 do_compile (void)
4611 /* Initialize timing first. The C front ends read the main file in
4612 the post_options hook, and C++ does file timings. */
4613 if (time_report || !quiet_flag || flag_detailed_statistics)
4614 timevar_init ();
4615 timevar_start (TV_TOTAL);
4617 process_options ();
4619 /* Don't do any more if an error has already occurred. */
4620 if (!errorcount)
4622 /* Set up the back-end if requested. */
4623 if (!no_backend)
4624 backend_init ();
4626 /* Language-dependent initialization. Returns true on success. */
4627 if (lang_dependent_init (main_input_filename))
4629 if (flag_unit_at_a_time)
4631 open_dump_file (DFI_cgraph, NULL);
4632 cgraph_dump_file = rtl_dump_file;
4633 rtl_dump_file = NULL;
4636 compile_file ();
4638 if (flag_unit_at_a_time)
4640 rtl_dump_file = cgraph_dump_file;
4641 cgraph_dump_file = NULL;
4642 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4646 finalize ();
4649 /* Stop timing and print the times. */
4650 timevar_stop (TV_TOTAL);
4651 timevar_print (stderr);
4654 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4655 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4656 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4658 It is not safe to call this function more than once. */
4661 toplev_main (unsigned int argc, const char **argv)
4663 save_argv = argv;
4665 /* Initialization of GCC's environment, and diagnostics. */
4666 general_init (argv[0]);
4668 /* Parse the options and do minimal processing; basically just
4669 enough to default flags appropriately. */
4670 decode_options (argc, argv);
4672 randomize ();
4674 /* Exit early if we can (e.g. -help). */
4675 if (!exit_after_options)
4676 do_compile ();
4678 if (errorcount || sorrycount)
4679 return (FATAL_EXIT_CODE);
4681 return (SUCCESS_EXIT_CODE);