* config/ia64/fde-glibc.c (_GNU_SOURCE): Define to 1 instead of
[official-gcc.git] / gcc / toplev.c
bloba1a1d73f3782a8c4c8f139816a1850784a679e53
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 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 "ssa.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
78 #include "cgraph.h"
79 #include "opts.h"
80 #include "coverage.h"
81 #include "value-prof.h"
83 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
84 #include "dwarf2out.h"
85 #endif
87 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
88 #include "dbxout.h"
89 #endif
91 #ifdef SDB_DEBUGGING_INFO
92 #include "sdbout.h"
93 #endif
95 #ifdef XCOFF_DEBUGGING_INFO
96 #include "xcoffout.h" /* Needed for external data
97 declarations for e.g. AIX 4.x. */
98 #endif
100 /* Carry information from ASM_DECLARE_OBJECT_NAME
101 to ASM_FINISH_DECLARE_OBJECT. */
103 extern int size_directive_output;
104 extern tree last_assemble_variable_decl;
106 extern void reg_alloc (void);
108 static void general_init (const char *);
109 static void do_compile (void);
110 static void process_options (void);
111 static void backend_init (void);
112 static int lang_dependent_init (const char *);
113 static void init_asm_output (const char *);
114 static void finalize (void);
116 static void crash_signal (int) ATTRIBUTE_NORETURN;
117 static void setup_core_dumping (void);
118 static void compile_file (void);
120 static int print_single_switch (FILE *, int, int, const char *,
121 const char *, const char *,
122 const char *, const char *);
123 static void print_switch_values (FILE *, int, int, const char *,
124 const char *, const char *);
126 /* Rest of compilation helper functions. */
127 static bool rest_of_handle_inlining (tree);
128 static rtx rest_of_handle_ssa (tree, rtx);
129 static void rest_of_handle_cse (tree, rtx);
130 static void rest_of_handle_cse2 (tree, rtx);
131 static void rest_of_handle_gcse (tree, rtx);
132 static void rest_of_handle_life (tree, rtx);
133 static void rest_of_handle_loop_optimize (tree, rtx);
134 static void rest_of_handle_loop2 (tree, rtx);
135 static void rest_of_handle_jump_bypass (tree, rtx);
136 static void rest_of_handle_sibling_calls (rtx);
137 static void rest_of_handle_null_pointer (tree, rtx);
138 static void rest_of_handle_addressof (tree, rtx);
139 static void rest_of_handle_cfg (tree, rtx);
140 static void rest_of_handle_branch_prob (tree, rtx);
141 static void rest_of_handle_value_profile_transformations (tree, rtx);
142 static void rest_of_handle_if_conversion (tree, rtx);
143 static void rest_of_handle_if_after_combine (tree, rtx);
144 static void rest_of_handle_tracer (tree, rtx);
145 static void rest_of_handle_combine (tree, rtx);
146 static void rest_of_handle_regmove (tree, rtx);
147 #ifdef INSN_SCHEDULING
148 static void rest_of_handle_sched (tree, rtx);
149 static void rest_of_handle_sched2 (tree, rtx);
150 #endif
151 static bool rest_of_handle_new_regalloc (tree, rtx, int *);
152 static bool rest_of_handle_old_regalloc (tree, rtx, int *);
153 static void rest_of_handle_regrename (tree, rtx);
154 static void rest_of_handle_reorder_blocks (tree, rtx);
155 #ifdef STACK_REGS
156 static void rest_of_handle_stack_regs (tree, rtx);
157 #endif
158 static void rest_of_handle_machine_reorg (tree, rtx);
159 #ifdef DELAY_SLOTS
160 static void rest_of_handle_delay_slots (tree, rtx);
161 #endif
162 static void rest_of_handle_final (tree, rtx);
164 /* Nonzero to dump debug info whilst parsing (-dy option). */
165 static int set_yydebug;
167 /* True if we don't need a backend (e.g. preprocessing only). */
168 static bool no_backend;
170 /* Length of line when printing switch values. */
171 #define MAX_LINE 75
173 /* Name of program invoked, sans directories. */
175 const char *progname;
177 /* Copy of argument vector to toplev_main. */
178 static const char **save_argv;
180 /* Name of top-level original source file (what was input to cpp).
181 This comes from the #-command at the beginning of the actual input.
182 If there isn't any there, then this is the cc1 input file name. */
184 const char *main_input_filename;
186 /* Current position in real source file. */
188 location_t input_location;
190 /* Nonzero if it is unsafe to create any new pseudo registers. */
191 int no_new_pseudos;
193 /* Stack of currently pending input files. */
195 struct file_stack *input_file_stack;
197 /* Incremented on each change to input_file_stack. */
198 int input_file_stack_tick;
200 /* Name to use as base of names for dump output files. */
202 const char *dump_base_name;
204 /* Name to use as a base for auxiliary output files. */
206 const char *aux_base_name;
208 /* Format to use to print dumpfile index value */
209 #ifndef DUMPFILE_FORMAT
210 #define DUMPFILE_FORMAT ".%02d."
211 #endif
213 /* Bit flags that specify the machine subtype we are compiling for.
214 Bits are tested using macros TARGET_... defined in the tm.h file
215 and set by `-m...' switches. Must be defined in rtlanal.c. */
217 extern int target_flags;
219 /* A mask of target_flags that includes bit X if X was set or cleared
220 on the command line. */
222 int target_flags_explicit;
224 /* Debug hooks - dependent upon command line options. */
226 const struct gcc_debug_hooks *debug_hooks;
228 /* Describes a dump file. */
230 struct dump_file_info
232 /* The unique extension to apply, e.g. ".jump". */
233 const char *const extension;
235 /* The -d<c> character that enables this dump file. */
236 char const debug_switch;
238 /* True if there is a corresponding graph dump file. */
239 char const graph_dump_p;
241 /* True if the user selected this dump. */
242 char enabled;
244 /* True if the files have been initialized (ie truncated). */
245 char initialized;
248 /* Enumerate the extant dump files. */
250 enum dump_file_index
252 DFI_cgraph,
253 DFI_rtl,
254 DFI_sibling,
255 DFI_eh,
256 DFI_jump,
257 DFI_ssa,
258 DFI_ssa_ccp,
259 DFI_ssa_dce,
260 DFI_ussa,
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_bbro,
287 DFI_ce3,
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 " m q "
302 " JK O Q Y "
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 { "ssa", 'e', 1, 0, 0 },
313 { "ssaccp", 'W', 1, 0, 0 },
314 { "ssadce", 'X', 1, 0, 0 },
315 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
316 { "null", 'u', 0, 0, 0 },
317 { "cse", 's', 0, 0, 0 },
318 { "addressof", 'F', 0, 0, 0 },
319 { "gcse", 'G', 1, 0, 0 },
320 { "loop", 'L', 1, 0, 0 },
321 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
322 { "cfg", 'f', 1, 0, 0 },
323 { "bp", 'b', 1, 0, 0 },
324 { "vpt", 'V', 1, 0, 0 },
325 { "ce1", 'C', 1, 0, 0 },
326 { "tracer", 'T', 1, 0, 0 },
327 { "loop2", 'L', 1, 0, 0 },
328 { "web", 'Z', 0, 0, 0 },
329 { "cse2", 't', 1, 0, 0 },
330 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
331 { "combine", 'c', 1, 0, 0 },
332 { "ce2", 'C', 1, 0, 0 },
333 { "regmove", 'N', 1, 0, 0 },
334 { "sched", 'S', 1, 0, 0 },
335 { "lreg", 'l', 1, 0, 0 },
336 { "greg", 'g', 1, 0, 0 },
337 { "postreload", 'o', 1, 0, 0 },
338 { "flow2", 'w', 1, 0, 0 },
339 { "peephole2", 'z', 1, 0, 0 },
340 { "rnreg", 'n', 1, 0, 0 },
341 { "bbro", 'B', 1, 0, 0 },
342 { "ce3", 'E', 1, 0, 0 },
343 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
344 { "sched2", 'R', 1, 0, 0 },
345 { "stack", 'k', 1, 0, 0 },
346 { "mach", 'M', 1, 0, 0 },
347 { "dbr", 'd', 0, 0, 0 },
350 static int open_dump_file (enum dump_file_index, tree);
351 static void close_dump_file (enum dump_file_index,
352 void (*) (FILE *, rtx), rtx);
354 /* Other flags saying which kinds of debugging dump have been requested. */
356 int rtl_dump_and_exit;
357 int flag_print_asm_name;
358 enum graph_dump_types graph_dump_format;
360 /* Name for output file of assembly code, specified with -o. */
362 const char *asm_file_name;
364 /* Nonzero means do optimizations. -O.
365 Particular numeric values stand for particular amounts of optimization;
366 thus, -O2 stores 2 here. However, the optimizations beyond the basic
367 ones are not controlled directly by this variable. Instead, they are
368 controlled by individual `flag_...' variables that are defaulted
369 based on this variable. */
371 int optimize = 0;
373 /* Nonzero means optimize for size. -Os.
374 The only valid values are zero and nonzero. When optimize_size is
375 nonzero, optimize defaults to 2, but certain individual code
376 bloating optimizations are disabled. */
378 int optimize_size = 0;
380 /* The FUNCTION_DECL for the function currently being compiled,
381 or 0 if between functions. */
382 tree current_function_decl;
384 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
385 if none. */
386 tree current_function_func_begin_label;
388 /* Nonzero if doing dwarf2 duplicate elimination. */
390 int flag_eliminate_dwarf2_dups = 0;
392 /* Nonzero if doing unused type elimination. */
394 int flag_eliminate_unused_debug_types = 1;
396 /* Nonzero means emit debugging information only for symbols which are used. */
397 int flag_debug_only_used_symbols = 0;
399 /* Nonzero if generating code to do profiling. */
401 int profile_flag = 0;
403 /* Nonzero if generating code to profile program flow graph arcs. */
405 int profile_arc_flag = 0;
407 /* Nonzero if value histograms should be measured. */
409 int flag_profile_values = 0;
411 /* Nonzero if value histograms should be used to optimize code. */
412 int flag_value_profile_transformations = 0;
414 /* Nonzero if generating info for gcov to calculate line test coverage. */
416 int flag_test_coverage = 0;
418 /* Nonzero indicates that branch taken probabilities should be calculated. */
420 int flag_branch_probabilities = 0;
422 /* Nonzero if basic blocks should be reordered. */
424 int flag_reorder_blocks = 0;
426 /* Nonzero if functions should be reordered. */
428 int flag_reorder_functions = 0;
430 /* Nonzero if registers should be renamed. */
432 int flag_rename_registers = 0;
433 int flag_cprop_registers = 0;
435 /* Nonzero for -pedantic switch: warn about anything
436 that standard spec forbids. */
438 int pedantic = 0;
440 /* Temporarily suppress certain warnings.
441 This is set while reading code from a system header file. */
443 int in_system_header = 0;
445 /* Don't print functions as they are compiled. -quiet. */
447 int quiet_flag = 0;
449 /* Print times taken by the various passes. -ftime-report. */
451 int time_report = 0;
453 /* Print memory still in use at end of compilation (which may have little
454 to do with peak memory consumption). -fmem-report. */
456 int mem_report = 0;
458 /* Nonzero means to collect statistics which might be expensive
459 and to print them when we are done. */
460 int flag_detailed_statistics = 0;
462 /* A random sequence of characters, unless overridden by user. */
463 const char *flag_random_seed;
465 /* A local time stamp derived from the time of compilation. It will be
466 zero if the system cannot provide a time. It will be -1u, if the
467 user has specified a particular random seed. */
468 unsigned local_tick;
470 /* -f flags. */
472 /* Nonzero means `char' should be signed. */
474 int flag_signed_char;
476 /* Nonzero means give an enum type only as many bytes as it needs. */
478 int flag_short_enums;
480 /* Nonzero for -fcaller-saves: allocate values in regs that need to
481 be saved across function calls, if that produces overall better code.
482 Optional now, so people can test it. */
484 #ifdef DEFAULT_CALLER_SAVES
485 int flag_caller_saves = 1;
486 #else
487 int flag_caller_saves = 0;
488 #endif
490 /* Nonzero if structures and unions should be returned in memory.
492 This should only be defined if compatibility with another compiler or
493 with an ABI is needed, because it results in slower code. */
495 #ifndef DEFAULT_PCC_STRUCT_RETURN
496 #define DEFAULT_PCC_STRUCT_RETURN 1
497 #endif
499 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
501 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
503 /* Nonzero for -fforce-mem: load memory value into a register
504 before arithmetic on it. This makes better cse but slower compilation. */
506 int flag_force_mem = 0;
508 /* Nonzero for -fforce-addr: load memory address into a register before
509 reference to memory. This makes better cse but slower compilation. */
511 int flag_force_addr = 0;
513 /* Nonzero for -fdefer-pop: don't pop args after each function call;
514 instead save them up to pop many calls' args with one insns. */
516 int flag_defer_pop = 0;
518 /* Nonzero for -ffloat-store: don't allocate floats and doubles
519 in extended-precision registers. */
521 int flag_float_store = 0;
523 /* Nonzero for -fcse-follow-jumps:
524 have cse follow jumps to do a more extensive job. */
526 int flag_cse_follow_jumps;
528 /* Nonzero for -fcse-skip-blocks:
529 have cse follow a branch around a block. */
530 int flag_cse_skip_blocks;
532 /* Nonzero for -fexpensive-optimizations:
533 perform miscellaneous relatively-expensive optimizations. */
534 int flag_expensive_optimizations;
536 /* Nonzero for -fthread-jumps:
537 have jump optimize output of loop. */
539 int flag_thread_jumps;
541 /* Nonzero enables strength-reduction in loop.c. */
543 int flag_strength_reduce = 0;
545 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
546 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
547 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
548 unrolled. */
550 int flag_old_unroll_loops;
552 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
553 This is generally not a win. */
555 int flag_old_unroll_all_loops;
557 /* Enables unrolling of simple loops in loop-unroll.c. */
558 int flag_unroll_loops;
560 /* Enables unrolling of all loops in loop-unroll.c. */
561 int flag_unroll_all_loops;
563 /* Nonzero enables loop peeling. */
564 int flag_peel_loops;
566 /* Nonzero enables loop unswitching. */
567 int flag_unswitch_loops;
569 /* Nonzero enables prefetch optimizations for arrays in loops. */
571 int flag_prefetch_loop_arrays;
573 /* Nonzero forces all invariant computations in loops to be moved
574 outside the loop. */
576 int flag_move_all_movables = 0;
578 /* Nonzero forces all general induction variables in loops to be
579 strength reduced. */
581 int flag_reduce_all_givs = 0;
583 /* Nonzero to perform full register move optimization passes. This is the
584 default for -O2. */
586 int flag_regmove = 0;
588 /* Nonzero for -fwritable-strings:
589 store string constants in data segment and don't uniquize them. */
591 int flag_writable_strings = 0;
593 /* Nonzero means don't put addresses of constant functions in registers.
594 Used for compiling the Unix kernel, where strange substitutions are
595 done on the assembly output. */
597 int flag_no_function_cse = 0;
599 /* Nonzero for -fomit-frame-pointer:
600 don't make a frame pointer in simple functions that don't require one. */
602 int flag_omit_frame_pointer = 0;
604 /* Nonzero means place each function into its own section on those platforms
605 which support arbitrary section names and unlimited numbers of sections. */
607 int flag_function_sections = 0;
609 /* ... and similar for data. */
611 int flag_data_sections = 0;
613 /* Nonzero to inhibit use of define_optimization peephole opts. */
615 int flag_no_peephole = 0;
617 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
619 int flag_optimize_sibling_calls = 0;
621 /* Nonzero means the front end generally wants `errno' maintained by math
622 operations, like built-in SQRT. */
624 int flag_errno_math = 1;
626 /* Nonzero means that unsafe floating-point math optimizations are allowed
627 for the sake of speed. IEEE compliance is not guaranteed, and operations
628 are allowed to assume that their arguments and results are "normal"
629 (e.g., nonnegative for SQRT). */
631 int flag_unsafe_math_optimizations = 0;
633 /* Nonzero means that no NaNs or +-Infs are expected. */
635 int flag_finite_math_only = 0;
637 /* Zero means that floating-point math operations cannot generate a
638 (user-visible) trap. This is the case, for example, in nonstop
639 IEEE 754 arithmetic. Trapping conditions include division by zero,
640 overflow, underflow, invalid and inexact, but does not include
641 operations on signaling NaNs (see below). */
643 int flag_trapping_math = 1;
645 /* Nonzero means disable transformations that assume default floating
646 point rounding behavior. */
648 int flag_rounding_math = 0;
650 /* Nonzero means disable transformations observable by signaling NaNs.
651 This option implies that any operation on an IEEE signaling NaN can
652 generate a (user-visible) trap. */
654 int flag_signaling_nans = 0;
656 /* 0 means straightforward implementation of complex divide acceptable.
657 1 means wide ranges of inputs must work for complex divide.
658 2 means C99-like requirements for complex divide (not yet implemented). */
660 int flag_complex_divide_method = 0;
662 /* Nonzero means just do syntax checking; don't output anything. */
664 int flag_syntax_only = 0;
666 /* Nonzero means performs web construction pass. */
668 int flag_web;
670 /* Nonzero means perform loop optimizer. */
672 int flag_loop_optimize;
674 /* Nonzero means perform crossjumping. */
676 int flag_crossjumping;
678 /* Nonzero means perform if conversion. */
680 int flag_if_conversion;
682 /* Nonzero means perform if conversion after reload. */
684 int flag_if_conversion2;
686 /* Nonzero means to use global dataflow analysis to eliminate
687 useless null pointer tests. */
689 int flag_delete_null_pointer_checks;
691 /* Nonzero means perform global CSE. */
693 int flag_gcse = 0;
695 /* Nonzero means to do the enhanced load motion during gcse, which trys
696 to hoist loads by not killing them when a store to the same location
697 is seen. */
699 int flag_gcse_lm = 1;
701 /* Nonzero means to perform store motion after gcse, which will try to
702 move stores closer to the exit block. Its not very effective without
703 flag_gcse_lm. */
705 int flag_gcse_sm = 1;
707 /* Nonzero if we want to perfrom redundant load after store elimination
708 in gcse. */
710 int flag_gcse_las = 1;
712 /* Perform target register optimization before prologue / epilogue
713 threading. */
715 int flag_branch_target_load_optimize = 0;
717 /* Perform target register optimization after prologue / epilogue
718 threading and jump2. */
720 int flag_branch_target_load_optimize2 = 0;
722 /* Nonzero means to rerun cse after loop optimization. This increases
723 compilation time about 20% and picks up a few more common expressions. */
725 int flag_rerun_cse_after_loop;
727 /* Nonzero means to run loop optimizations twice. */
729 int flag_rerun_loop_opt;
731 /* Nonzero for -finline-functions: ok to inline functions that look like
732 good inline candidates. */
734 int flag_inline_functions;
736 /* Nonzero for -fkeep-inline-functions: even if we make a function
737 go inline everywhere, keep its definition around for debugging
738 purposes. */
740 int flag_keep_inline_functions;
742 /* Nonzero means that functions will not be inlined. */
744 int flag_no_inline = 2;
746 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
747 not just because the tree inliner turned us off. */
749 int flag_really_no_inline = 2;
751 /* Nonzero means that we should emit static const variables
752 regardless of whether or not optimization is turned on. */
754 int flag_keep_static_consts = 1;
756 /* Nonzero means we should be saving declaration info into a .X file. */
758 int flag_gen_aux_info = 0;
760 /* Specified name of aux-info file. */
762 const char *aux_info_file_name;
764 /* Nonzero means make the text shared if supported. */
766 int flag_shared_data;
768 /* Nonzero means schedule into delayed branch slots if supported. */
770 int flag_delayed_branch;
772 /* Nonzero if we are compiling pure (sharable) code.
773 Value is 1 if we are doing "small" pic; value is 2 if we're doing
774 "large" pic. */
776 int flag_pic;
778 /* Nonzero if we are compiling position independent code for executable.
779 The value is 1 if we are doing "small" pic; value is 2 if we're doing
780 "large" pic. */
782 int flag_pie;
784 /* Nonzero if we are compiling code for a shared library, zero for
785 executable. */
787 int flag_shlib;
789 /* Set to the default thread-local storage (tls) model to use. */
791 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
793 /* Nonzero means generate extra code for exception handling and enable
794 exception handling. */
796 int flag_exceptions;
798 /* Nonzero means generate frame unwind info table when supported. */
800 int flag_unwind_tables = 0;
802 /* Nonzero means generate frame unwind info table exact at each insn
803 boundary. */
805 int flag_asynchronous_unwind_tables = 0;
807 /* Nonzero means don't place uninitialized global data in common storage
808 by default. */
810 int flag_no_common;
812 /* Nonzero means change certain warnings into errors.
813 Usually these are warnings about failure to conform to some standard. */
815 int flag_pedantic_errors = 0;
817 /* flag_schedule_insns means schedule insns within basic blocks (before
818 local_alloc).
819 flag_schedule_insns_after_reload means schedule insns after
820 global_alloc. */
822 int flag_schedule_insns = 0;
823 int flag_schedule_insns_after_reload = 0;
825 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
826 int flag_sched2_use_superblocks = 0;
828 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
829 scheduler. */
830 int flag_sched2_use_traces = 0;
832 /* The following flags have effect only for scheduling before register
833 allocation:
835 flag_schedule_interblock means schedule insns across basic blocks.
836 flag_schedule_speculative means allow speculative motion of non-load insns.
837 flag_schedule_speculative_load means allow speculative motion of some
838 load insns.
839 flag_schedule_speculative_load_dangerous allows speculative motion of more
840 load insns. */
842 int flag_schedule_interblock = 1;
843 int flag_schedule_speculative = 1;
844 int flag_schedule_speculative_load = 0;
845 int flag_schedule_speculative_load_dangerous = 0;
847 /* The following flags have an effect during scheduling after register
848 allocation:
850 flag_sched_stalled_insns means that insns can be moved prematurely from the queue
851 of stalled insns into the ready list.
853 flag_sched_stalled_insns_dep controls how many insn groups will be examined
854 for a dependency on a stalled insn that is candidate for premature removal
855 from the queue of stalled insns into the ready list (has an effect only if
856 the flag 'sched_stalled_insns' is set). */
858 int flag_sched_stalled_insns = 0;
859 int flag_sched_stalled_insns_dep = 1;
861 int flag_single_precision_constant;
863 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
864 by a cheaper branch on a count register. */
865 int flag_branch_on_count_reg = 1;
867 /* -finhibit-size-directive inhibits output of .size for ELF.
868 This is used only for compiling crtstuff.c,
869 and it may be extended to other effects
870 needed for crtstuff.c on other systems. */
871 int flag_inhibit_size_directive = 0;
873 /* -fverbose-asm causes extra commentary information to be produced in
874 the generated assembly code (to make it more readable). This option
875 is generally only of use to those who actually need to read the
876 generated assembly code (perhaps while debugging the compiler itself).
877 -fno-verbose-asm, the default, causes the extra information
878 to be omitted and is useful when comparing two assembler files. */
880 int flag_verbose_asm = 0;
882 /* -dA causes debug commentary information to be produced in
883 the generated assembly code (to make it more readable). This option
884 is generally only of use to those who actually need to read the
885 generated assembly code (perhaps while debugging the compiler itself).
886 Currently, this switch is only used by dwarfout.c; however, it is intended
887 to be a catchall for printing debug information in the assembler file. */
889 int flag_debug_asm = 0;
891 /* -dP causes the rtl to be emitted as a comment in assembly. */
893 int flag_dump_rtl_in_asm = 0;
895 /* -fgnu-linker specifies use of the GNU linker for initializations.
896 (Or, more generally, a linker that handles initializations.)
897 -fno-gnu-linker says that collect2 will be used. */
898 #ifdef USE_COLLECT2
899 int flag_gnu_linker = 0;
900 #else
901 int flag_gnu_linker = 1;
902 #endif
904 /* Nonzero means put zero initialized data in the bss section. */
905 int flag_zero_initialized_in_bss = 1;
907 /* Enable SSA. */
908 int flag_ssa = 0;
910 /* Enable ssa conditional constant propagation. */
911 int flag_ssa_ccp = 0;
913 /* Enable ssa aggressive dead code elimination. */
914 int flag_ssa_dce = 0;
916 /* Tag all structures with __attribute__(packed). */
917 int flag_pack_struct = 0;
919 /* Emit code to check for stack overflow; also may cause large objects
920 to be allocated dynamically. */
921 int flag_stack_check;
923 /* When non-NULL, indicates that whenever space is allocated on the
924 stack, the resulting stack pointer must not pass this
925 address---that is, for stacks that grow downward, the stack pointer
926 must always be greater than or equal to this address; for stacks
927 that grow upward, the stack pointer must be less than this address.
928 At present, the rtx may be either a REG or a SYMBOL_REF, although
929 the support provided depends on the backend. */
930 rtx stack_limit_rtx;
932 /* 0 if pointer arguments may alias each other. True in C.
933 1 if pointer arguments may not alias each other but may alias
934 global variables.
935 2 if pointer arguments may not alias each other and may not
936 alias global variables. True in Fortran.
937 This defaults to 0 for C. */
938 int flag_argument_noalias = 0;
940 /* Nonzero if we should do (language-dependent) alias analysis.
941 Typically, this analysis will assume that expressions of certain
942 types do not alias expressions of certain other types. Only used
943 if alias analysis (in general) is enabled. */
944 int flag_strict_aliasing = 0;
946 /* Instrument functions with calls at entry and exit, for profiling. */
947 int flag_instrument_function_entry_exit = 0;
949 /* Nonzero means ignore `#ident' directives. 0 means handle them.
950 On SVR4 targets, it also controls whether or not to emit a
951 string identifying the compiler. */
953 int flag_no_ident = 0;
955 /* This will perform a peephole pass before sched2. */
956 int flag_peephole2 = 0;
958 /* This will try to guess branch probabilities. */
959 int flag_guess_branch_prob = 0;
961 /* -fcheck-bounds causes gcc to generate array bounds checks.
962 For C, C++, ObjC: defaults to off.
963 For Java: defaults to on.
964 For Fortran: defaults to off. */
965 int flag_bounds_check = 0;
967 /* This will attempt to merge constant section constants, if 1 only
968 string constants and constants from constant pool, if 2 also constant
969 variables. */
970 int flag_merge_constants = 1;
972 /* If one, renumber instruction UIDs to reduce the number of
973 unused UIDs if there are a lot of instructions. If greater than
974 one, unconditionally renumber instruction UIDs. */
975 int flag_renumber_insns = 1;
977 /* If nonzero, use the graph coloring register allocator. */
978 int flag_new_regalloc = 0;
980 /* Nonzero if we perform superblock formation. */
982 int flag_tracer = 0;
984 /* Nonzero if we perform whole unit at a time compilation. */
986 int flag_unit_at_a_time = 0;
988 /* Values of the -falign-* flags: how much to align labels in code.
989 0 means `use default', 1 means `don't align'.
990 For each variable, there is an _log variant which is the power
991 of two not less than the variable, for .align output. */
993 int align_loops;
994 int align_loops_log;
995 int align_loops_max_skip;
996 int align_jumps;
997 int align_jumps_log;
998 int align_jumps_max_skip;
999 int align_labels;
1000 int align_labels_log;
1001 int align_labels_max_skip;
1002 int align_functions;
1003 int align_functions_log;
1005 /* Like align_functions_log above, but used by front-ends to force the
1006 minimum function alignment. Zero means no alignment is forced. */
1007 int force_align_functions_log;
1009 typedef struct
1011 const char *const string;
1012 int *const variable;
1013 const int on_value;
1015 lang_independent_options;
1017 /* Nonzero if signed arithmetic overflow should trap. */
1018 int flag_trapv = 0;
1020 /* Nonzero if signed arithmetic overflow should wrap around. */
1021 int flag_wrapv = 0;
1023 /* Nonzero if subexpressions must be evaluated from left-to-right. */
1024 int flag_evaluation_order = 0;
1026 /* Add or remove a leading underscore from user symbols. */
1027 int flag_leading_underscore = -1;
1029 /* The user symbol prefix after having resolved same. */
1030 const char *user_label_prefix;
1032 static const param_info lang_independent_params[] = {
1033 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1034 { OPTION, DEFAULT, HELP },
1035 #include "params.def"
1036 #undef DEFPARAM
1037 { NULL, 0, NULL }
1040 /* Table of language-independent -f options.
1041 STRING is the option name. VARIABLE is the address of the variable.
1042 ON_VALUE is the value to store in VARIABLE
1043 if `-fSTRING' is seen as an option.
1044 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1046 static const lang_independent_options f_options[] =
1048 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1049 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1050 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1051 {"float-store", &flag_float_store, 1 },
1052 {"defer-pop", &flag_defer_pop, 1 },
1053 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1054 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1055 {"tracer", &flag_tracer, 1 },
1056 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1057 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1058 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1059 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1060 {"thread-jumps", &flag_thread_jumps, 1 },
1061 {"strength-reduce", &flag_strength_reduce, 1 },
1062 {"unroll-loops", &flag_unroll_loops, 1 },
1063 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1064 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1065 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1066 {"peel-loops", &flag_peel_loops, 1 },
1067 {"unswitch-loops", &flag_unswitch_loops, 1 },
1068 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1069 {"move-all-movables", &flag_move_all_movables, 1 },
1070 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1071 {"writable-strings", &flag_writable_strings, 1 },
1072 {"peephole", &flag_no_peephole, 0 },
1073 {"force-mem", &flag_force_mem, 1 },
1074 {"force-addr", &flag_force_addr, 1 },
1075 {"function-cse", &flag_no_function_cse, 0 },
1076 {"inline-functions", &flag_inline_functions, 1 },
1077 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1078 {"inline", &flag_no_inline, 0 },
1079 {"keep-static-consts", &flag_keep_static_consts, 1 },
1080 {"syntax-only", &flag_syntax_only, 1 },
1081 {"shared-data", &flag_shared_data, 1 },
1082 {"caller-saves", &flag_caller_saves, 1 },
1083 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1084 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1085 {"delayed-branch", &flag_delayed_branch, 1 },
1086 {"web", &flag_web, 1},
1087 {"gcse", &flag_gcse, 1 },
1088 {"gcse-lm", &flag_gcse_lm, 1 },
1089 {"gcse-sm", &flag_gcse_sm, 1 },
1090 {"gcse-las", &flag_gcse_las, 1 },
1091 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1092 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1093 {"loop-optimize", &flag_loop_optimize, 1 },
1094 {"crossjumping", &flag_crossjumping, 1 },
1095 {"if-conversion", &flag_if_conversion, 1 },
1096 {"if-conversion2", &flag_if_conversion2, 1 },
1097 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1098 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1099 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1100 {"schedule-insns", &flag_schedule_insns, 1 },
1101 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1102 {"sched-interblock",&flag_schedule_interblock, 1 },
1103 {"sched-spec",&flag_schedule_speculative, 1 },
1104 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1105 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1106 {"sched-stalled-insns", &flag_sched_stalled_insns, 0 },
1107 {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 },
1108 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1109 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1110 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1111 {"pic", &flag_pic, 1 },
1112 {"PIC", &flag_pic, 2 },
1113 {"pie", &flag_pie, 1 },
1114 {"PIE", &flag_pie, 2 },
1115 {"exceptions", &flag_exceptions, 1 },
1116 {"unwind-tables", &flag_unwind_tables, 1 },
1117 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1118 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1119 {"profile-arcs", &profile_arc_flag, 1 },
1120 {"profile-values", &flag_profile_values, 1 },
1121 {"vpt", &flag_value_profile_transformations, 1 },
1122 {"test-coverage", &flag_test_coverage, 1 },
1123 {"branch-probabilities", &flag_branch_probabilities, 1 },
1124 {"profile", &profile_flag, 1 },
1125 {"reorder-blocks", &flag_reorder_blocks, 1 },
1126 {"reorder-functions", &flag_reorder_functions, 1 },
1127 {"rename-registers", &flag_rename_registers, 1 },
1128 {"cprop-registers", &flag_cprop_registers, 1 },
1129 {"common", &flag_no_common, 0 },
1130 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1131 {"function-sections", &flag_function_sections, 1 },
1132 {"data-sections", &flag_data_sections, 1 },
1133 {"verbose-asm", &flag_verbose_asm, 1 },
1134 {"gnu-linker", &flag_gnu_linker, 1 },
1135 {"regmove", &flag_regmove, 1 },
1136 {"optimize-register-move", &flag_regmove, 1 },
1137 {"pack-struct", &flag_pack_struct, 1 },
1138 {"stack-check", &flag_stack_check, 1 },
1139 {"argument-alias", &flag_argument_noalias, 0 },
1140 {"argument-noalias", &flag_argument_noalias, 1 },
1141 {"argument-noalias-global", &flag_argument_noalias, 2 },
1142 {"strict-aliasing", &flag_strict_aliasing, 1 },
1143 {"align-loops", &align_loops, 0 },
1144 {"align-jumps", &align_jumps, 0 },
1145 {"align-labels", &align_labels, 0 },
1146 {"align-functions", &align_functions, 0 },
1147 {"merge-constants", &flag_merge_constants, 1 },
1148 {"merge-all-constants", &flag_merge_constants, 2 },
1149 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1150 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1151 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1152 {"ssa", &flag_ssa, 1 },
1153 {"ssa-ccp", &flag_ssa_ccp, 1 },
1154 {"ssa-dce", &flag_ssa_dce, 1 },
1155 {"leading-underscore", &flag_leading_underscore, 1 },
1156 {"ident", &flag_no_ident, 0 },
1157 { "peephole2", &flag_peephole2, 1 },
1158 {"finite-math-only", &flag_finite_math_only, 1 },
1159 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1160 {"math-errno", &flag_errno_math, 1 },
1161 {"trapping-math", &flag_trapping_math, 1 },
1162 {"rounding-math", &flag_rounding_math, 1 },
1163 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1164 {"signaling-nans", &flag_signaling_nans, 1 },
1165 {"bounds-check", &flag_bounds_check, 1 },
1166 {"single-precision-constant", &flag_single_precision_constant, 1 },
1167 {"time-report", &time_report, 1 },
1168 {"mem-report", &mem_report, 1 },
1169 { "trapv", &flag_trapv, 1 },
1170 { "wrapv", &flag_wrapv, 1 },
1171 { "new-ra", &flag_new_regalloc, 1 }
1174 /* Here is a table, controlled by the tm.h file, listing each -m switch
1175 and which bits in `target_switches' it should set or clear.
1176 If VALUE is positive, it is bits to set.
1177 If VALUE is negative, -VALUE is bits to clear.
1178 (The sign bit is not used so there is no confusion.) */
1180 static const struct
1182 const char *const name;
1183 const int value;
1184 const char *const description;
1186 target_switches[] = TARGET_SWITCHES;
1188 /* This table is similar, but allows the switch to have a value. */
1190 #ifdef TARGET_OPTIONS
1191 static const struct
1193 const char *const prefix;
1194 const char **const variable;
1195 const char *const description;
1196 const char *const value;
1198 target_options[] = TARGET_OPTIONS;
1199 #endif
1201 /* Nonzero means warn about function definitions that default the return type
1202 or that use a null return and have a return-type other than void. */
1204 int warn_return_type;
1206 /* Output files for assembler code (real compiler output)
1207 and debugging dumps. */
1209 FILE *asm_out_file;
1210 FILE *aux_info_file;
1211 FILE *rtl_dump_file = NULL;
1212 FILE *cgraph_dump_file = NULL;
1214 /* The current working directory of a translation. It's generally the
1215 directory from which compilation was initiated, but a preprocessed
1216 file may specify the original directory in which it was
1217 created. */
1219 static const char *src_pwd;
1221 /* Initialize src_pwd with the given string, and return true. If it
1222 was already initialized, return false. As a special case, it may
1223 be called with a NULL argument to test whether src_pwd has NOT been
1224 initialized yet. */
1226 bool
1227 set_src_pwd (const char *pwd)
1229 if (src_pwd)
1230 return false;
1232 src_pwd = xstrdup (pwd);
1233 return true;
1236 /* Return the directory from which the translation unit was initiated,
1237 in case set_src_pwd() was not called before to assign it a
1238 different value. */
1240 const char *
1241 get_src_pwd (void)
1243 if (! src_pwd)
1244 src_pwd = getpwd ();
1246 return src_pwd;
1249 /* Called when the start of a function definition is parsed,
1250 this function prints on stderr the name of the function. */
1251 void
1252 announce_function (tree decl)
1254 if (!quiet_flag)
1256 if (rtl_dump_and_exit)
1257 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1258 else
1259 verbatim (" %s", (*lang_hooks.decl_printable_name) (decl, 2));
1260 fflush (stderr);
1261 pp_needs_newline (global_dc->printer) = true;
1262 diagnostic_set_last_function (global_dc);
1266 /* Set up a default flag_random_seed and local_tick, unless the user
1267 already specified one. */
1269 static void
1270 randomize (void)
1272 if (!flag_random_seed)
1274 unsigned HOST_WIDE_INT value;
1275 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1277 /* Get some more or less random data. */
1278 #ifdef HAVE_GETTIMEOFDAY
1280 struct timeval tv;
1282 gettimeofday (&tv, NULL);
1283 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1285 #else
1287 time_t now = time (NULL);
1289 if (now != (time_t)-1)
1290 local_tick = (unsigned) now;
1292 #endif
1293 value = local_tick ^ getpid ();
1295 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1296 flag_random_seed = random_seed;
1298 else if (!local_tick)
1299 local_tick = -1;
1303 /* Decode the string P as an integral parameter.
1304 If the string is indeed an integer return its numeric value else
1305 issue an Invalid Option error for the option PNAME and return DEFVAL.
1306 If PNAME is zero just return DEFVAL, do not call error. */
1309 read_integral_parameter (const char *p, const char *pname, const int defval)
1311 const char *endp = p;
1313 while (*endp)
1315 if (ISDIGIT (*endp))
1316 endp++;
1317 else
1318 break;
1321 if (*endp != 0)
1323 if (pname != 0)
1324 error ("invalid option argument `%s'", pname);
1325 return defval;
1328 return atoi (p);
1331 /* Return the logarithm of X, base 2, considering X unsigned,
1332 if X is a power of 2. Otherwise, returns -1.
1334 This should be used via the `exact_log2' macro. */
1337 exact_log2_wide (unsigned HOST_WIDE_INT x)
1339 int log = 0;
1340 /* Test for 0 or a power of 2. */
1341 if (x == 0 || x != (x & -x))
1342 return -1;
1343 while ((x >>= 1) != 0)
1344 log++;
1345 return log;
1348 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1349 If X is 0, return -1.
1351 This should be used via the floor_log2 macro. */
1354 floor_log2_wide (unsigned HOST_WIDE_INT x)
1356 int log = -1;
1357 while (x != 0)
1358 log++,
1359 x >>= 1;
1360 return log;
1363 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1364 into ICE messages, which is much more user friendly. In case the
1365 error printer crashes, reset the signal to prevent infinite recursion. */
1367 static void
1368 crash_signal (int signo)
1370 signal (signo, SIG_DFL);
1371 internal_error ("%s", strsignal (signo));
1374 /* Arrange to dump core on error. (The regular error message is still
1375 printed first, except in the case of abort().) */
1377 static void
1378 setup_core_dumping (void)
1380 #ifdef SIGABRT
1381 signal (SIGABRT, SIG_DFL);
1382 #endif
1383 #if defined(HAVE_SETRLIMIT)
1385 struct rlimit rlim;
1386 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1387 fatal_error ("getting core file size maximum limit: %m");
1388 rlim.rlim_cur = rlim.rlim_max;
1389 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1390 fatal_error ("setting core file size limit to maximum: %m");
1392 #endif
1393 diagnostic_abort_on_error (global_dc);
1397 /* Strip off a legitimate source ending from the input string NAME of
1398 length LEN. Rather than having to know the names used by all of
1399 our front ends, we strip off an ending of a period followed by
1400 up to five characters. (Java uses ".class".) */
1402 void
1403 strip_off_ending (char *name, int len)
1405 int i;
1406 for (i = 2; i < 6 && len > i; i++)
1408 if (name[len - i] == '.')
1410 name[len - i] = '\0';
1411 break;
1416 /* Output a quoted string. */
1418 void
1419 output_quoted_string (FILE *asm_file, const char *string)
1421 #ifdef OUTPUT_QUOTED_STRING
1422 OUTPUT_QUOTED_STRING (asm_file, string);
1423 #else
1424 char c;
1426 putc ('\"', asm_file);
1427 while ((c = *string++) != 0)
1429 if (ISPRINT (c))
1431 if (c == '\"' || c == '\\')
1432 putc ('\\', asm_file);
1433 putc (c, asm_file);
1435 else
1436 fprintf (asm_file, "\\%03o", (unsigned char) c);
1438 putc ('\"', asm_file);
1439 #endif
1442 /* Output a file name in the form wanted by System V. */
1444 void
1445 output_file_directive (FILE *asm_file, const char *input_name)
1447 int len;
1448 const char *na;
1450 if (input_name == NULL)
1451 input_name = "<stdin>";
1453 len = strlen (input_name);
1454 na = input_name + len;
1456 /* NA gets INPUT_NAME sans directory names. */
1457 while (na > input_name)
1459 if (IS_DIR_SEPARATOR (na[-1]))
1460 break;
1461 na--;
1464 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1465 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1466 #else
1467 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1468 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1469 #else
1470 fprintf (asm_file, "\t.file\t");
1471 output_quoted_string (asm_file, na);
1472 fputc ('\n', asm_file);
1473 #endif
1474 #endif
1477 /* Routine to open a dump file. Return true if the dump file is enabled. */
1479 static int
1480 open_dump_file (enum dump_file_index index, tree decl)
1482 char *dump_name;
1483 const char *open_arg;
1484 char seq[16];
1486 if (! dump_file[index].enabled)
1487 return 0;
1489 timevar_push (TV_DUMP);
1490 if (rtl_dump_file != NULL)
1491 fclose (rtl_dump_file);
1493 sprintf (seq, DUMPFILE_FORMAT, index);
1495 if (! dump_file[index].initialized)
1497 /* If we've not initialized the files, do so now. */
1498 if (graph_dump_format != no_graph
1499 && dump_file[index].graph_dump_p)
1501 dump_name = concat (seq, dump_file[index].extension, NULL);
1502 clean_graph_dump_file (dump_base_name, dump_name);
1503 free (dump_name);
1505 dump_file[index].initialized = 1;
1506 open_arg = "w";
1508 else
1509 open_arg = "a";
1511 dump_name = concat (dump_base_name, seq,
1512 dump_file[index].extension, NULL);
1514 rtl_dump_file = fopen (dump_name, open_arg);
1515 if (rtl_dump_file == NULL)
1516 fatal_error ("can't open %s: %m", dump_name);
1518 free (dump_name);
1520 if (decl)
1521 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1522 (*lang_hooks.decl_printable_name) (decl, 2),
1523 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1524 ? " (hot)"
1525 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1526 ? " (unlikely executed)"
1527 : "");
1529 timevar_pop (TV_DUMP);
1530 return 1;
1533 /* Routine to close a dump file. */
1535 static void
1536 close_dump_file (enum dump_file_index index,
1537 void (*func) (FILE *, rtx),
1538 rtx insns)
1540 if (! rtl_dump_file)
1541 return;
1543 timevar_push (TV_DUMP);
1544 if (insns
1545 && graph_dump_format != no_graph
1546 && dump_file[index].graph_dump_p)
1548 char seq[16];
1549 char *suffix;
1551 sprintf (seq, DUMPFILE_FORMAT, index);
1552 suffix = concat (seq, dump_file[index].extension, NULL);
1553 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1554 free (suffix);
1557 if (func && insns)
1558 func (rtl_dump_file, insns);
1560 fflush (rtl_dump_file);
1561 fclose (rtl_dump_file);
1563 rtl_dump_file = NULL;
1564 timevar_pop (TV_DUMP);
1567 /* Do any final processing required for the declarations in VEC, of
1568 which there are LEN. We write out inline functions and variables
1569 that have been deferred until this point, but which are required.
1570 Returns nonzero if anything was put out. */
1573 wrapup_global_declarations (tree *vec, int len)
1575 tree decl;
1576 int i;
1577 int reconsider;
1578 int output_something = 0;
1580 for (i = 0; i < len; i++)
1582 decl = vec[i];
1584 /* We're not deferring this any longer. Assignment is
1585 conditional to avoid needlessly dirtying PCH pages. */
1586 if (DECL_DEFER_OUTPUT (decl) != 0)
1587 DECL_DEFER_OUTPUT (decl) = 0;
1589 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1590 (*lang_hooks.finish_incomplete_decl) (decl);
1593 /* Now emit any global variables or functions that we have been
1594 putting off. We need to loop in case one of the things emitted
1595 here references another one which comes earlier in the list. */
1598 reconsider = 0;
1599 for (i = 0; i < len; i++)
1601 decl = vec[i];
1603 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1604 continue;
1606 /* Don't write out static consts, unless we still need them.
1608 We also keep static consts if not optimizing (for debugging),
1609 unless the user specified -fno-keep-static-consts.
1610 ??? They might be better written into the debug information.
1611 This is possible when using DWARF.
1613 A language processor that wants static constants to be always
1614 written out (even if it is not used) is responsible for
1615 calling rest_of_decl_compilation itself. E.g. the C front-end
1616 calls rest_of_decl_compilation from finish_decl.
1617 One motivation for this is that is conventional in some
1618 environments to write things like:
1619 static const char rcsid[] = "... version string ...";
1620 intending to force the string to be in the executable.
1622 A language processor that would prefer to have unneeded
1623 static constants "optimized away" would just defer writing
1624 them out until here. E.g. C++ does this, because static
1625 constants are often defined in header files.
1627 ??? A tempting alternative (for both C and C++) would be
1628 to force a constant to be written if and only if it is
1629 defined in a main file, as opposed to an include file. */
1631 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1633 bool needed = 1;
1635 if (flag_unit_at_a_time
1636 && cgraph_varpool_node (decl)->finalized)
1637 needed = 0;
1638 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
1639 && (TREE_USED (decl)
1640 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1641 /* needed */;
1642 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1643 /* needed */;
1644 else if (DECL_COMDAT (decl))
1645 needed = 0;
1646 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1647 && (optimize || !flag_keep_static_consts
1648 || DECL_ARTIFICIAL (decl)))
1649 needed = 0;
1651 if (needed)
1653 reconsider = 1;
1654 rest_of_decl_compilation (decl, NULL, 1, 1);
1658 if (TREE_CODE (decl) == FUNCTION_DECL
1659 && DECL_INITIAL (decl) != 0
1660 && DECL_SAVED_INSNS (decl) != 0
1661 && DECL_SAVED_INSNS (decl)->saved_for_inline
1662 && (flag_keep_inline_functions
1663 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1664 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1666 reconsider = 1;
1667 output_inline_function (decl);
1671 if (reconsider)
1672 output_something = 1;
1674 while (reconsider);
1676 return output_something;
1679 /* Issue appropriate warnings for the global declarations in VEC (of
1680 which there are LEN). Output debugging information for them. */
1682 void
1683 check_global_declarations (tree *vec, int len)
1685 tree decl;
1686 int i;
1688 for (i = 0; i < len; i++)
1690 decl = vec[i];
1692 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1693 && ! TREE_ASM_WRITTEN (decl))
1694 /* Cancel the RTL for this decl so that, if debugging info
1695 output for global variables is still to come,
1696 this one will be omitted. */
1697 SET_DECL_RTL (decl, NULL_RTX);
1699 /* Warn about any function
1700 declared static but not defined.
1701 We don't warn about variables,
1702 because many programs have static variables
1703 that exist only to get some text into the object file. */
1704 if (TREE_CODE (decl) == FUNCTION_DECL
1705 && (warn_unused_function
1706 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1707 && DECL_INITIAL (decl) == 0
1708 && DECL_EXTERNAL (decl)
1709 && ! DECL_ARTIFICIAL (decl)
1710 && ! TREE_PUBLIC (decl))
1712 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1713 pedwarn ("%J'%F' used but never defined", decl, decl);
1714 else
1715 warning ("%J'%F' declared `static' but never defined", decl, decl);
1716 /* This symbol is effectively an "extern" declaration now. */
1717 TREE_PUBLIC (decl) = 1;
1718 assemble_external (decl);
1721 /* Warn about static fns or vars defined but not used. */
1722 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1723 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
1724 && ! TREE_USED (decl)
1725 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1726 to handle multiple external decls in different scopes. */
1727 && ! TREE_USED (DECL_NAME (decl))
1728 && ! DECL_EXTERNAL (decl)
1729 && ! TREE_PUBLIC (decl)
1730 /* A volatile variable might be used in some non-obvious way. */
1731 && ! TREE_THIS_VOLATILE (decl)
1732 /* Global register variables must be declared to reserve them. */
1733 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1734 /* Otherwise, ask the language. */
1735 && (*lang_hooks.decls.warn_unused_global) (decl))
1736 warning ("%J'%D' defined but not used", decl, decl);
1738 /* Avoid confusing the debug information machinery when there are
1739 errors. */
1740 if (errorcount == 0 && sorrycount == 0)
1742 timevar_push (TV_SYMOUT);
1743 (*debug_hooks->global_decl) (decl);
1744 timevar_pop (TV_SYMOUT);
1749 /* Warn about a use of an identifier which was marked deprecated. */
1750 void
1751 warn_deprecated_use (tree node)
1753 if (node == 0 || !warn_deprecated_decl)
1754 return;
1756 if (DECL_P (node))
1757 warning ("`%s' is deprecated (declared at %s:%d)",
1758 IDENTIFIER_POINTER (DECL_NAME (node)),
1759 DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node));
1760 else if (TYPE_P (node))
1762 const char *what = NULL;
1763 tree decl = TYPE_STUB_DECL (node);
1765 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
1766 what = IDENTIFIER_POINTER (TYPE_NAME (node));
1767 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
1768 && DECL_NAME (TYPE_NAME (node)))
1769 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
1771 if (what)
1773 if (decl)
1774 warning ("`%s' is deprecated (declared at %s:%d)", what,
1775 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1776 else
1777 warning ("`%s' is deprecated", what);
1779 else if (decl)
1780 warning ("type is deprecated (declared at %s:%d)",
1781 DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
1782 else
1783 warning ("type is deprecated");
1787 /* Save the current INPUT_LOCATION on the top entry in the
1788 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1789 INPUT_LOCATION accordingly. */
1791 void
1792 push_srcloc (const char *file, int line)
1794 struct file_stack *fs;
1796 fs = xmalloc (sizeof (struct file_stack));
1797 fs->location = input_location;
1798 fs->next = input_file_stack;
1799 input_filename = file;
1800 input_line = line;
1801 input_file_stack = fs;
1802 input_file_stack_tick++;
1805 /* Pop the top entry off the stack of presently open source files.
1806 Restore the INPUT_LOCATION from the new topmost entry on the
1807 stack. */
1809 void
1810 pop_srcloc (void)
1812 struct file_stack *fs;
1814 fs = input_file_stack;
1815 input_location = fs->location;
1816 input_file_stack = fs->next;
1817 free (fs);
1818 input_file_stack_tick++;
1821 /* Compile an entire translation unit. Write a file of assembly
1822 output and various debugging dumps. */
1824 static void
1825 compile_file (void)
1827 /* Initialize yet another pass. */
1829 init_final (main_input_filename);
1830 coverage_init (aux_base_name);
1832 timevar_push (TV_PARSE);
1834 /* Call the parser, which parses the entire file (calling
1835 rest_of_compilation for each function). */
1836 (*lang_hooks.parse_file) (set_yydebug);
1838 /* In case there were missing block closers,
1839 get us back to the global binding level. */
1840 (*lang_hooks.clear_binding_stack) ();
1842 /* Compilation is now finished except for writing
1843 what's left of the symbol table output. */
1844 timevar_pop (TV_PARSE);
1846 if (flag_syntax_only)
1847 return;
1849 (*lang_hooks.decls.final_write_globals)();
1851 cgraph_varpool_assemble_pending_decls ();
1853 /* This must occur after the loop to output deferred functions.
1854 Else the coverage initializer would not be emitted if all the
1855 functions in this compilation unit were deferred. */
1856 coverage_finish ();
1858 /* Write out any pending weak symbol declarations. */
1860 weak_finish ();
1862 /* Do dbx symbols. */
1863 timevar_push (TV_SYMOUT);
1865 #ifdef DWARF2_UNWIND_INFO
1866 if (dwarf2out_do_frame ())
1867 dwarf2out_frame_finish ();
1868 #endif
1870 (*debug_hooks->finish) (main_input_filename);
1871 timevar_pop (TV_SYMOUT);
1873 /* Output some stuff at end of file if nec. */
1875 dw2_output_indirect_constants ();
1877 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1879 timevar_push (TV_DUMP);
1880 open_dump_file (DFI_bp, NULL);
1882 end_branch_prob ();
1884 close_dump_file (DFI_bp, NULL, NULL_RTX);
1885 timevar_pop (TV_DUMP);
1888 targetm.asm_out.file_end ();
1890 /* Attach a special .ident directive to the end of the file to identify
1891 the version of GCC which compiled this code. The format of the .ident
1892 string is patterned after the ones produced by native SVR4 compilers. */
1893 #ifdef IDENT_ASM_OP
1894 if (!flag_no_ident)
1895 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1896 IDENT_ASM_OP, version_string);
1897 #endif
1899 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1901 timevar_push (TV_DUMP);
1902 dump_combine_total_stats (rtl_dump_file);
1903 close_dump_file (DFI_combine, NULL, NULL_RTX);
1904 timevar_pop (TV_DUMP);
1908 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1909 and TYPE_DECL nodes.
1911 This does nothing for local (non-static) variables, unless the
1912 variable is a register variable with an ASMSPEC. In that case, or
1913 if the variable is not an automatic, it sets up the RTL and
1914 outputs any assembler code (label definition, storage allocation
1915 and initialization).
1917 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1918 the assembler symbol name to be used. TOP_LEVEL is nonzero
1919 if this declaration is not within a function. */
1921 void
1922 rest_of_decl_compilation (tree decl,
1923 const char *asmspec,
1924 int top_level,
1925 int at_end)
1927 /* We deferred calling assemble_alias so that we could collect
1928 other attributes such as visibility. Emit the alias now. */
1930 tree alias;
1931 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1932 if (alias)
1934 alias = TREE_VALUE (TREE_VALUE (alias));
1935 alias = get_identifier (TREE_STRING_POINTER (alias));
1936 assemble_alias (decl, alias);
1940 /* Forward declarations for nested functions are not "external",
1941 but we need to treat them as if they were. */
1942 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1943 || TREE_CODE (decl) == FUNCTION_DECL)
1945 timevar_push (TV_VARCONST);
1947 if (asmspec)
1948 make_decl_rtl (decl, asmspec);
1950 /* Don't output anything when a tentative file-scope definition
1951 is seen. But at end of compilation, do output code for them. */
1952 if ((at_end || !DECL_DEFER_OUTPUT (decl)) && !DECL_EXTERNAL (decl))
1954 if (flag_unit_at_a_time && !cgraph_global_info_ready
1955 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1956 cgraph_varpool_finalize_decl (decl);
1957 else
1958 assemble_variable (decl, top_level, at_end, 0);
1961 #ifdef ASM_FINISH_DECLARE_OBJECT
1962 if (decl == last_assemble_variable_decl)
1964 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1965 top_level, at_end);
1967 #endif
1969 timevar_pop (TV_VARCONST);
1971 else if (DECL_REGISTER (decl) && asmspec != 0)
1973 if (decode_reg_name (asmspec) >= 0)
1975 SET_DECL_RTL (decl, NULL_RTX);
1976 make_decl_rtl (decl, asmspec);
1978 else
1980 error ("invalid register name `%s' for register variable", asmspec);
1981 DECL_REGISTER (decl) = 0;
1982 if (!top_level)
1983 expand_decl (decl);
1986 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1987 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1988 && TREE_CODE (decl) == TYPE_DECL)
1990 timevar_push (TV_SYMOUT);
1991 dbxout_symbol (decl, 0);
1992 timevar_pop (TV_SYMOUT);
1994 #endif
1995 #ifdef SDB_DEBUGGING_INFO
1996 else if (write_symbols == SDB_DEBUG && top_level
1997 && TREE_CODE (decl) == TYPE_DECL)
1999 timevar_push (TV_SYMOUT);
2000 sdbout_symbol (decl, 0);
2001 timevar_pop (TV_SYMOUT);
2003 #endif
2004 #ifdef DWARF2_DEBUGGING_INFO
2005 else if ((write_symbols == DWARF2_DEBUG
2006 || write_symbols == VMS_AND_DWARF2_DEBUG)
2007 && top_level
2008 && TREE_CODE (decl) == TYPE_DECL)
2010 timevar_push (TV_SYMOUT);
2011 dwarf2out_decl (decl);
2012 timevar_pop (TV_SYMOUT);
2014 #endif
2017 /* Called after finishing a record, union or enumeral type. */
2019 void
2020 rest_of_type_compilation (
2021 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
2022 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
2023 tree type,
2024 int toplev
2025 #else
2026 tree type ATTRIBUTE_UNUSED,
2027 int toplev ATTRIBUTE_UNUSED
2028 #endif
2031 /* Avoid confusing the debug information machinery when there are
2032 errors. */
2033 if (errorcount != 0 || sorrycount != 0)
2034 return;
2036 timevar_push (TV_SYMOUT);
2037 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2038 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2039 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
2040 #endif
2041 #ifdef SDB_DEBUGGING_INFO
2042 if (write_symbols == SDB_DEBUG)
2043 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
2044 #endif
2045 #ifdef DWARF2_DEBUGGING_INFO
2046 if ((write_symbols == DWARF2_DEBUG
2047 || write_symbols == VMS_AND_DWARF2_DEBUG)
2048 && toplev)
2049 dwarf2out_decl (TYPE_STUB_DECL (type));
2050 #endif
2051 timevar_pop (TV_SYMOUT);
2054 /* Turn the RTL into assembly. */
2055 static void
2056 rest_of_handle_final (tree decl, rtx insns)
2058 timevar_push (TV_FINAL);
2060 rtx x;
2061 const char *fnname;
2063 /* Get the function's name, as described by its RTL. This may be
2064 different from the DECL_NAME name used in the source file. */
2066 x = DECL_RTL (decl);
2067 if (GET_CODE (x) != MEM)
2068 abort ();
2069 x = XEXP (x, 0);
2070 if (GET_CODE (x) != SYMBOL_REF)
2071 abort ();
2072 fnname = XSTR (x, 0);
2074 assemble_start_function (decl, fnname);
2075 final_start_function (insns, asm_out_file, optimize);
2076 final (insns, asm_out_file, optimize, 0);
2077 final_end_function ();
2079 #ifdef IA64_UNWIND_INFO
2080 /* ??? The IA-64 ".handlerdata" directive must be issued before
2081 the ".endp" directive that closes the procedure descriptor. */
2082 output_function_exception_table ();
2083 #endif
2085 assemble_end_function (decl, fnname);
2087 #ifndef IA64_UNWIND_INFO
2088 /* Otherwise, it feels unclean to switch sections in the middle. */
2089 output_function_exception_table ();
2090 #endif
2092 if (! quiet_flag)
2093 fflush (asm_out_file);
2095 /* Release all memory allocated by flow. */
2096 free_basic_block_vars (0);
2098 /* Release all memory held by regsets now. */
2099 regset_release_memory ();
2101 timevar_pop (TV_FINAL);
2103 ggc_collect ();
2106 #ifdef DELAY_SLOTS
2107 /* Run delay slot optimization. */
2108 static void
2109 rest_of_handle_delay_slots (tree decl, rtx insns)
2111 timevar_push (TV_DBR_SCHED);
2112 open_dump_file (DFI_dbr, decl);
2114 dbr_schedule (insns, rtl_dump_file);
2116 close_dump_file (DFI_dbr, print_rtl, insns);
2117 timevar_pop (TV_DBR_SCHED);
2119 ggc_collect ();
2121 #endif
2123 #ifdef STACK_REGS
2124 /* Convert register usage from flat register file usage to a stack
2125 register file. */
2126 static void
2127 rest_of_handle_stack_regs (tree decl, rtx insns)
2129 #if defined (HAVE_ATTR_length)
2130 /* If flow2 creates new instructions which need splitting
2131 and scheduling after reload is not done, they might not be
2132 splitten until final which doesn't allow splitting
2133 if HAVE_ATTR_length. */
2134 #ifdef INSN_SCHEDULING
2135 if (optimize && !flag_schedule_insns_after_reload)
2136 #else
2137 if (optimize)
2138 #endif
2140 timevar_push (TV_SHORTEN_BRANCH);
2141 split_all_insns (1);
2142 timevar_pop (TV_SHORTEN_BRANCH);
2144 #endif
2146 timevar_push (TV_REG_STACK);
2147 open_dump_file (DFI_stack, decl);
2149 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2151 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2152 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2153 && flag_reorder_blocks)
2155 reorder_basic_blocks ();
2156 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2160 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2161 timevar_pop (TV_REG_STACK);
2163 ggc_collect ();
2165 #endif
2168 /* Machine independent reorg pass. */
2169 static void
2170 rest_of_handle_machine_reorg (tree decl, rtx insns)
2172 timevar_push (TV_MACH_DEP);
2173 open_dump_file (DFI_mach, decl);
2175 (*targetm.machine_dependent_reorg) ();
2177 close_dump_file (DFI_mach, print_rtl, insns);
2178 timevar_pop (TV_MACH_DEP);
2180 ggc_collect ();
2184 /* Run new register allocator. Return TRUE if we must exit
2185 rest_of_compilation upon return. */
2186 static bool
2187 rest_of_handle_new_regalloc (tree decl, rtx insns, int *rebuild_notes)
2189 int failure;
2191 delete_trivially_dead_insns (insns, max_reg_num ());
2192 reg_alloc ();
2194 timevar_pop (TV_LOCAL_ALLOC);
2195 if (dump_file[DFI_lreg].enabled)
2197 timevar_push (TV_DUMP);
2199 close_dump_file (DFI_lreg, NULL, NULL);
2200 timevar_pop (TV_DUMP);
2203 /* XXX clean up the whole mess to bring live info in shape again. */
2204 timevar_push (TV_GLOBAL_ALLOC);
2205 open_dump_file (DFI_greg, decl);
2207 build_insn_chain (insns);
2208 failure = reload (insns, 0);
2210 timevar_pop (TV_GLOBAL_ALLOC);
2212 if (dump_file[DFI_greg].enabled)
2214 timevar_push (TV_DUMP);
2216 dump_global_regs (rtl_dump_file);
2218 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2219 timevar_pop (TV_DUMP);
2222 if (failure)
2223 return true;
2225 reload_completed = 1;
2226 *rebuild_notes = 0;
2228 return false;
2231 /* Run old register allocator. Return TRUE if we must exit
2232 rest_of_compilation upon return. */
2233 static bool
2234 rest_of_handle_old_regalloc (tree decl, rtx insns, int *rebuild_notes)
2236 int failure;
2238 /* Allocate the reg_renumber array. */
2239 allocate_reg_info (max_regno, FALSE, TRUE);
2241 /* And the reg_equiv_memory_loc array. */
2242 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2244 allocate_initial_values (reg_equiv_memory_loc);
2246 regclass (insns, max_reg_num (), rtl_dump_file);
2247 *rebuild_notes = local_alloc ();
2249 timevar_pop (TV_LOCAL_ALLOC);
2251 if (dump_file[DFI_lreg].enabled)
2253 timevar_push (TV_DUMP);
2255 dump_flow_info (rtl_dump_file);
2256 dump_local_alloc (rtl_dump_file);
2258 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2259 timevar_pop (TV_DUMP);
2262 ggc_collect ();
2264 timevar_push (TV_GLOBAL_ALLOC);
2265 open_dump_file (DFI_greg, decl);
2267 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2268 pass fixing up any insns that are invalid. */
2270 if (optimize)
2271 failure = global_alloc (rtl_dump_file);
2272 else
2274 build_insn_chain (insns);
2275 failure = reload (insns, 0);
2278 timevar_pop (TV_GLOBAL_ALLOC);
2280 if (dump_file[DFI_greg].enabled)
2282 timevar_push (TV_DUMP);
2284 dump_global_regs (rtl_dump_file);
2286 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2287 timevar_pop (TV_DUMP);
2290 return failure;
2293 /* Run the regrename and cprop passes. */
2294 static void
2295 rest_of_handle_regrename (tree decl, rtx insns)
2297 timevar_push (TV_RENAME_REGISTERS);
2298 open_dump_file (DFI_rnreg, decl);
2300 if (flag_rename_registers)
2301 regrename_optimize ();
2302 if (flag_cprop_registers)
2303 copyprop_hardreg_forward ();
2305 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2306 timevar_pop (TV_RENAME_REGISTERS);
2309 /* Reorder basic blocks. */
2310 static void
2311 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2313 timevar_push (TV_REORDER_BLOCKS);
2314 open_dump_file (DFI_bbro, decl);
2316 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2317 splitting possibly introduced more crossjumping opportunities. */
2318 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2319 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2321 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2322 tracer ();
2323 if (flag_reorder_blocks)
2324 reorder_basic_blocks ();
2325 if (flag_reorder_blocks
2326 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2327 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2329 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2330 timevar_pop (TV_REORDER_BLOCKS);
2333 #ifdef INSN_SCHEDULING
2334 /* Run instruction scheduler. */
2335 static void
2336 rest_of_handle_sched (tree decl, rtx insns)
2338 timevar_push (TV_SCHED);
2340 /* Print function header into sched dump now
2341 because doing the sched analysis makes some of the dump. */
2342 if (optimize > 0 && flag_schedule_insns)
2344 open_dump_file (DFI_sched, decl);
2346 /* Do control and data sched analysis,
2347 and write some of the results to dump file. */
2349 schedule_insns (rtl_dump_file);
2351 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2353 timevar_pop (TV_SCHED);
2355 ggc_collect ();
2358 /* Run second scheduling pass after reload. */
2359 static void
2360 rest_of_handle_sched2 (tree decl, rtx insns)
2362 timevar_push (TV_SCHED2);
2363 open_dump_file (DFI_sched2, decl);
2365 /* Do control and data sched analysis again,
2366 and write some more of the results to dump file. */
2368 split_all_insns (1);
2370 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2372 schedule_ebbs (rtl_dump_file);
2373 /* No liveness updating code yet, but it should be easy to do.
2374 reg-stack recompute the liveness when needed for now. */
2375 count_or_remove_death_notes (NULL, 1);
2376 cleanup_cfg (CLEANUP_EXPENSIVE);
2378 else
2379 schedule_insns (rtl_dump_file);
2381 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2382 timevar_pop (TV_SCHED2);
2384 ggc_collect ();
2386 #endif
2388 /* Register allocation pre-pass, to reduce number of moves necessary
2389 for two-address machines. */
2390 static void
2391 rest_of_handle_regmove (tree decl, rtx insns)
2393 timevar_push (TV_REGMOVE);
2394 open_dump_file (DFI_regmove, decl);
2396 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2398 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2399 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2400 timevar_pop (TV_REGMOVE);
2402 ggc_collect ();
2405 /* Run tracer. */
2406 static void
2407 rest_of_handle_tracer (tree decl, rtx insns)
2409 timevar_push (TV_TRACER);
2410 open_dump_file (DFI_tracer, decl);
2411 if (rtl_dump_file)
2412 dump_flow_info (rtl_dump_file);
2413 tracer ();
2414 cleanup_cfg (CLEANUP_EXPENSIVE);
2415 reg_scan (insns, max_reg_num (), 0);
2416 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2417 timevar_pop (TV_TRACER);
2420 /* If-conversion and CFG cleanup. */
2421 static void
2422 rest_of_handle_if_conversion (tree decl, rtx insns)
2424 open_dump_file (DFI_ce1, decl);
2425 if (flag_if_conversion)
2427 timevar_push (TV_IFCVT);
2428 if (rtl_dump_file)
2429 dump_flow_info (rtl_dump_file);
2430 cleanup_cfg (CLEANUP_EXPENSIVE);
2431 reg_scan (insns, max_reg_num (), 0);
2432 if_convert (0);
2433 timevar_pop (TV_IFCVT);
2435 timevar_push (TV_JUMP);
2436 cleanup_cfg (CLEANUP_EXPENSIVE);
2437 reg_scan (insns, max_reg_num (), 0);
2438 timevar_pop (TV_JUMP);
2439 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2442 /* Rerun if-conversion, as combine may have simplified things enough
2443 to now meet sequence length restrictions. */
2444 static void
2445 rest_of_handle_if_after_combine (tree decl, rtx insns)
2447 timevar_push (TV_IFCVT);
2448 open_dump_file (DFI_ce2, decl);
2450 no_new_pseudos = 0;
2451 if_convert (1);
2452 no_new_pseudos = 1;
2454 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2455 timevar_pop (TV_IFCVT);
2458 static void
2459 rest_of_handle_web (tree decl, rtx insns)
2461 open_dump_file (DFI_web, decl);
2462 timevar_push (TV_WEB);
2463 web_main ();
2464 delete_trivially_dead_insns (insns, max_reg_num ());
2465 cleanup_cfg (CLEANUP_EXPENSIVE);
2467 timevar_pop (TV_WEB);
2468 close_dump_file (DFI_web, print_rtl_with_bb, insns);
2469 reg_scan (get_insns (), max_reg_num (), 0);
2472 /* Do branch profiling and static profile estimation passes. */
2473 static void
2474 rest_of_handle_branch_prob (tree decl, rtx insns)
2476 struct loops loops;
2478 timevar_push (TV_BRANCH_PROB);
2479 open_dump_file (DFI_bp, decl);
2481 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2482 branch_prob ();
2484 /* Discover and record the loop depth at the head of each basic
2485 block. The loop infrastructure does the real job for us. */
2486 flow_loops_find (&loops, LOOP_TREE);
2488 if (rtl_dump_file)
2489 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2491 /* Estimate using heuristics if no profiling info is available. */
2492 if (flag_guess_branch_prob)
2493 estimate_probability (&loops);
2495 flow_loops_free (&loops);
2496 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2497 timevar_pop (TV_BRANCH_PROB);
2500 /* Do optimizations based on expression value profiles. */
2501 static void
2502 rest_of_handle_value_profile_transformations (tree decl, rtx insns)
2504 open_dump_file (DFI_vpt, decl);
2505 timevar_push (TV_VPT);
2507 if (value_profile_transformations ())
2508 cleanup_cfg (CLEANUP_EXPENSIVE);
2510 timevar_pop (TV_VPT);
2511 close_dump_file (DFI_vpt, print_rtl_with_bb, insns);
2514 /* Do control and data flow analysis; write some of the results to the
2515 dump file. */
2516 static void
2517 rest_of_handle_cfg (tree decl, rtx insns)
2519 open_dump_file (DFI_cfg, decl);
2520 if (rtl_dump_file)
2521 dump_flow_info (rtl_dump_file);
2522 if (optimize)
2523 cleanup_cfg (CLEANUP_EXPENSIVE
2524 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2526 /* It may make more sense to mark constant functions after dead code is
2527 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2528 may insert code making function non-constant, but we still must consider
2529 it as constant, otherwise -fbranch-probabilities will not read data back.
2531 life_analysis rarely eliminates modification of external memory.
2533 if (optimize)
2534 mark_constant_function ();
2536 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2539 /* Purge addressofs. */
2540 static void
2541 rest_of_handle_addressof (tree decl, rtx insns)
2543 open_dump_file (DFI_addressof, decl);
2545 purge_addressof (insns);
2546 if (optimize && purge_all_dead_edges (0))
2547 delete_unreachable_blocks ();
2548 reg_scan (insns, max_reg_num (), 1);
2550 close_dump_file (DFI_addressof, print_rtl, insns);
2553 /* We may have potential sibling or tail recursion sites. Select one
2554 (of possibly multiple) methods of performing the call. */
2555 static void
2556 rest_of_handle_sibling_calls (rtx insns)
2558 rtx insn;
2559 optimize_sibling_and_tail_recursive_calls ();
2561 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2562 free_bb_for_insn ();
2563 find_exception_handler_labels ();
2564 rebuild_jump_labels (insns);
2565 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2567 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2568 notes before simplifying cfg and we must do lowering after sibcall
2569 that unhides parts of RTL chain and cleans up the CFG.
2571 Until sibcall is replaced by tree-level optimizer, lets just
2572 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2573 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2574 if (GET_CODE (insn) == NOTE
2575 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2576 delete_insn (insn);
2578 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2581 /* Perform jump bypassing and control flow optimizations. */
2582 static void
2583 rest_of_handle_jump_bypass (tree decl, rtx insns)
2585 timevar_push (TV_BYPASS);
2586 open_dump_file (DFI_bypass, decl);
2588 cleanup_cfg (CLEANUP_EXPENSIVE);
2590 if (bypass_jumps (rtl_dump_file))
2592 rebuild_jump_labels (insns);
2593 cleanup_cfg (CLEANUP_EXPENSIVE);
2594 delete_trivially_dead_insns (insns, max_reg_num ());
2597 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2598 timevar_pop (TV_BYPASS);
2600 ggc_collect ();
2602 #ifdef ENABLE_CHECKING
2603 verify_flow_info ();
2604 #endif
2607 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2608 if we must exit rest_of_compilation upon return. */
2609 static bool
2610 rest_of_handle_inlining (tree decl)
2612 rtx insns;
2613 int inlinable = 0;
2614 tree parent;
2615 const char *lose;
2617 /* If we are reconsidering an inline function at the end of
2618 compilation, skip the stuff for making it inline. */
2619 if (cfun->rtl_inline_init)
2620 return 0;
2621 cfun->rtl_inline_init = 1;
2623 /* If this is nested inside an inlined external function, pretend
2624 it was only declared. Since we cannot inline such functions,
2625 generating code for this one is not only not necessary but will
2626 confuse some debugging output writers. */
2627 for (parent = DECL_CONTEXT (current_function_decl);
2628 parent != NULL_TREE;
2629 parent = get_containing_scope (parent))
2630 if (TREE_CODE (parent) == FUNCTION_DECL
2631 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2633 DECL_INITIAL (decl) = 0;
2634 return true;
2636 else if (TYPE_P (parent))
2637 /* A function in a local class should be treated normally. */
2638 break;
2640 /* If requested, consider whether to make this function inline. */
2641 if ((DECL_INLINE (decl) && !flag_no_inline)
2642 || flag_inline_functions)
2644 timevar_push (TV_INTEGRATION);
2645 lose = function_cannot_inline_p (decl);
2646 timevar_pop (TV_INTEGRATION);
2647 if (lose || ! optimize)
2649 if (warn_inline && lose && DECL_INLINE (decl))
2651 char *msg = concat ("%J", lose, NULL);
2652 warning (msg, decl);
2653 free (msg);
2655 DECL_ABSTRACT_ORIGIN (decl) = 0;
2656 /* Don't really compile an extern inline function.
2657 If we can't make it inline, pretend
2658 it was only declared. */
2659 if (DECL_EXTERNAL (decl))
2661 DECL_INITIAL (decl) = 0;
2662 return true;
2665 else
2666 inlinable = DECL_INLINE (decl) = 1;
2669 insns = get_insns ();
2671 /* Dump the rtl code if we are dumping rtl. */
2673 if (open_dump_file (DFI_rtl, decl))
2675 if (DECL_SAVED_INSNS (decl) && DECL_SAVED_INSNS (decl)->saved_for_inline)
2676 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2677 close_dump_file (DFI_rtl, print_rtl, insns);
2680 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2681 sorts of eh initialization. Delay this until after the
2682 initial rtl dump so that we can see the original nesting. */
2683 convert_from_eh_region_ranges ();
2685 /* If function is inline, and we don't yet know whether to
2686 compile it by itself, defer decision till end of compilation.
2687 wrapup_global_declarations will (indirectly) call
2688 rest_of_compilation again for those functions that need to
2689 be output. Also defer those functions that we are supposed
2690 to defer. */
2692 if (inlinable
2693 || (DECL_INLINE (decl)
2694 && flag_inline_functions
2695 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2696 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2697 && ! flag_keep_inline_functions)
2698 || DECL_EXTERNAL (decl))))
2699 DECL_DEFER_OUTPUT (decl) = 1;
2701 if (DECL_INLINE (decl))
2702 /* DWARF wants separate debugging info for abstract and
2703 concrete instances of all inline functions, including those
2704 declared inline but not inlined, and those inlined even
2705 though they weren't declared inline. Conveniently, that's
2706 what DECL_INLINE means at this point. */
2707 (*debug_hooks->deferred_inline_function) (decl);
2709 if (DECL_DEFER_OUTPUT (decl))
2711 /* If -Wreturn-type, we have to do a bit of compilation. We just
2712 want to call cleanup the cfg to figure out whether or not we can
2713 fall off the end of the function; we do the minimum amount of
2714 work necessary to make that safe. */
2715 if (warn_return_type)
2717 int saved_optimize = optimize;
2719 optimize = 0;
2720 rebuild_jump_labels (insns);
2721 find_exception_handler_labels ();
2722 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2723 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2724 optimize = saved_optimize;
2726 /* CFG is no longer maintained up-to-date. */
2727 free_bb_for_insn ();
2730 set_nothrow_function_flags ();
2731 if (current_function_nothrow)
2732 /* Now we know that this can't throw; set the flag for the benefit
2733 of other functions later in this translation unit. */
2734 TREE_NOTHROW (current_function_decl) = 1;
2736 timevar_push (TV_INTEGRATION);
2737 save_for_inline (decl);
2738 timevar_pop (TV_INTEGRATION);
2739 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2740 return true;
2743 /* If specified extern inline but we aren't inlining it, we are
2744 done. This goes for anything that gets here with DECL_EXTERNAL
2745 set, not just things with DECL_INLINE. */
2746 return (bool) DECL_EXTERNAL (decl);
2749 /* Rest of compilation helper to convert the rtl to SSA form. */
2750 static rtx
2751 rest_of_handle_ssa (tree decl, rtx insns)
2753 timevar_push (TV_TO_SSA);
2754 open_dump_file (DFI_ssa, decl);
2756 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2757 convert_to_ssa ();
2759 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2760 timevar_pop (TV_TO_SSA);
2762 /* Perform sparse conditional constant propagation, if requested. */
2763 if (flag_ssa_ccp)
2765 timevar_push (TV_SSA_CCP);
2766 open_dump_file (DFI_ssa_ccp, decl);
2768 ssa_const_prop ();
2770 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2771 timevar_pop (TV_SSA_CCP);
2774 /* It would be useful to cleanup the CFG at this point, but block
2775 merging and possibly other transformations might leave a PHI
2776 node in the middle of a basic block, which is a strict no-no. */
2778 /* The SSA implementation uses basic block numbers in its phi
2779 nodes. Thus, changing the control-flow graph or the basic
2780 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2781 may cause problems. */
2783 if (flag_ssa_dce)
2785 /* Remove dead code. */
2787 timevar_push (TV_SSA_DCE);
2788 open_dump_file (DFI_ssa_dce, decl);
2790 insns = get_insns ();
2791 ssa_eliminate_dead_code ();
2793 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2794 timevar_pop (TV_SSA_DCE);
2797 /* Convert from SSA form. */
2799 timevar_push (TV_FROM_SSA);
2800 open_dump_file (DFI_ussa, decl);
2802 convert_from_ssa ();
2803 /* New registers have been created. Rescan their usage. */
2804 reg_scan (insns, max_reg_num (), 1);
2806 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2807 timevar_pop (TV_FROM_SSA);
2809 ggc_collect ();
2811 return insns;
2814 /* Try to identify useless null pointer tests and delete them. */
2815 static void
2816 rest_of_handle_null_pointer (tree decl, rtx insns)
2818 open_dump_file (DFI_null, decl);
2819 if (rtl_dump_file)
2820 dump_flow_info (rtl_dump_file);
2822 if (delete_null_pointer_checks (insns))
2823 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2825 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2828 /* Try combining insns through substitution. */
2829 static void
2830 rest_of_handle_combine (tree decl, rtx insns)
2832 int rebuild_jump_labels_after_combine = 0;
2834 timevar_push (TV_COMBINE);
2835 open_dump_file (DFI_combine, decl);
2837 rebuild_jump_labels_after_combine
2838 = combine_instructions (insns, max_reg_num ());
2840 /* Combining insns may have turned an indirect jump into a
2841 direct jump. Rebuild the JUMP_LABEL fields of jumping
2842 instructions. */
2843 if (rebuild_jump_labels_after_combine)
2845 timevar_push (TV_JUMP);
2846 rebuild_jump_labels (insns);
2847 timevar_pop (TV_JUMP);
2849 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2852 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2853 timevar_pop (TV_COMBINE);
2855 ggc_collect ();
2858 /* Perform life analysis. */
2859 static void
2860 rest_of_handle_life (tree decl, rtx insns)
2862 open_dump_file (DFI_life, decl);
2863 regclass_init ();
2865 #ifdef ENABLE_CHECKING
2866 verify_flow_info ();
2867 #endif
2868 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2869 if (optimize)
2870 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2871 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2872 timevar_pop (TV_FLOW);
2874 if (warn_uninitialized)
2876 uninitialized_vars_warning (DECL_INITIAL (decl));
2877 if (extra_warnings)
2878 setjmp_args_warning ();
2881 if (optimize)
2883 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2885 /* Insns were inserted, and possibly pseudos created, so
2886 things might look a bit different. */
2887 insns = get_insns ();
2888 allocate_reg_life_data ();
2889 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2890 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2894 no_new_pseudos = 1;
2896 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2898 ggc_collect ();
2901 /* Perform common subexpression elimination. Nonzero value from
2902 `cse_main' means that jumps were simplified and some code may now
2903 be unreachable, so do jump optimization again. */
2904 static void
2905 rest_of_handle_cse (tree decl, rtx insns)
2907 int tem;
2909 open_dump_file (DFI_cse, decl);
2910 if (rtl_dump_file)
2911 dump_flow_info (rtl_dump_file);
2912 timevar_push (TV_CSE);
2914 reg_scan (insns, max_reg_num (), 1);
2916 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2917 if (tem)
2918 rebuild_jump_labels (insns);
2919 if (purge_all_dead_edges (0))
2920 delete_unreachable_blocks ();
2922 delete_trivially_dead_insns (insns, max_reg_num ());
2924 /* If we are not running more CSE passes, then we are no longer
2925 expecting CSE to be run. But always rerun it in a cheap mode. */
2926 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2928 if (tem || optimize > 1)
2929 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2930 /* Try to identify useless null pointer tests and delete them. */
2931 if (flag_delete_null_pointer_checks)
2933 timevar_push (TV_JUMP);
2935 if (delete_null_pointer_checks (insns))
2936 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2937 timevar_pop (TV_JUMP);
2940 /* The second pass of jump optimization is likely to have
2941 removed a bunch more instructions. */
2942 renumber_insns (rtl_dump_file);
2944 timevar_pop (TV_CSE);
2945 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2948 /* Run second CSE pass after loop optimizations. */
2949 static void
2950 rest_of_handle_cse2 (tree decl, rtx insns)
2952 int tem;
2954 timevar_push (TV_CSE2);
2955 open_dump_file (DFI_cse2, decl);
2956 if (rtl_dump_file)
2957 dump_flow_info (rtl_dump_file);
2958 /* CFG is no longer maintained up-to-date. */
2959 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2960 purge_all_dead_edges (0);
2961 delete_trivially_dead_insns (insns, max_reg_num ());
2963 if (tem)
2965 timevar_push (TV_JUMP);
2966 rebuild_jump_labels (insns);
2967 cleanup_cfg (CLEANUP_EXPENSIVE);
2968 timevar_pop (TV_JUMP);
2970 reg_scan (insns, max_reg_num (), 0);
2971 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2972 ggc_collect ();
2973 timevar_pop (TV_CSE2);
2976 /* Perform global cse. */
2977 static void
2978 rest_of_handle_gcse (tree decl, rtx insns)
2980 int save_csb, save_cfj;
2981 int tem2 = 0, tem;
2983 timevar_push (TV_GCSE);
2984 open_dump_file (DFI_gcse, decl);
2986 tem = gcse_main (insns, rtl_dump_file);
2987 rebuild_jump_labels (insns);
2988 delete_trivially_dead_insns (insns, max_reg_num ());
2990 save_csb = flag_cse_skip_blocks;
2991 save_cfj = flag_cse_follow_jumps;
2992 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2994 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2995 if (current_function_calls_constant_p)
2996 purge_builtin_constant_p ();
2998 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2999 by gcse. */
3000 if (flag_expensive_optimizations)
3002 timevar_push (TV_CSE);
3003 reg_scan (insns, max_reg_num (), 1);
3004 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3005 purge_all_dead_edges (0);
3006 delete_trivially_dead_insns (insns, max_reg_num ());
3007 timevar_pop (TV_CSE);
3008 cse_not_expected = !flag_rerun_cse_after_loop;
3011 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
3012 things up. Then possibly re-run CSE again. */
3013 while (tem || tem2)
3015 tem = tem2 = 0;
3016 timevar_push (TV_JUMP);
3017 rebuild_jump_labels (insns);
3018 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3019 timevar_pop (TV_JUMP);
3021 if (flag_expensive_optimizations)
3023 timevar_push (TV_CSE);
3024 reg_scan (insns, max_reg_num (), 1);
3025 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
3026 purge_all_dead_edges (0);
3027 delete_trivially_dead_insns (insns, max_reg_num ());
3028 timevar_pop (TV_CSE);
3032 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
3033 timevar_pop (TV_GCSE);
3035 ggc_collect ();
3036 flag_cse_skip_blocks = save_csb;
3037 flag_cse_follow_jumps = save_cfj;
3038 #ifdef ENABLE_CHECKING
3039 verify_flow_info ();
3040 #endif
3043 /* Move constant computations out of loops. */
3044 static void
3045 rest_of_handle_loop_optimize (tree decl, rtx insns)
3047 int do_unroll, do_prefetch;
3049 timevar_push (TV_LOOP);
3050 delete_dead_jumptables ();
3051 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3052 open_dump_file (DFI_loop, decl);
3054 /* CFG is no longer maintained up-to-date. */
3055 free_bb_for_insn ();
3057 if (flag_unroll_loops)
3058 do_unroll = 0; /* Having two unrollers is useless. */
3059 else
3060 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
3061 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
3063 if (flag_rerun_loop_opt)
3065 cleanup_barriers ();
3067 /* We only want to perform unrolling once. */
3068 loop_optimize (insns, rtl_dump_file, do_unroll);
3069 do_unroll = 0;
3071 /* The first call to loop_optimize makes some instructions
3072 trivially dead. We delete those instructions now in the
3073 hope that doing so will make the heuristics in loop work
3074 better and possibly speed up compilation. */
3075 delete_trivially_dead_insns (insns, max_reg_num ());
3077 /* The regscan pass is currently necessary as the alias
3078 analysis code depends on this information. */
3079 reg_scan (insns, max_reg_num (), 1);
3081 cleanup_barriers ();
3082 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
3084 /* Loop can create trivially dead instructions. */
3085 delete_trivially_dead_insns (insns, max_reg_num ());
3086 close_dump_file (DFI_loop, print_rtl, insns);
3087 timevar_pop (TV_LOOP);
3088 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3090 ggc_collect ();
3093 /* Perform loop optimizations. It might be better to do them a bit
3094 sooner, but we want the profile feedback to work more
3095 efficiently. */
3096 static void
3097 rest_of_handle_loop2 (tree decl, rtx insns)
3099 struct loops *loops;
3100 timevar_push (TV_LOOP);
3101 open_dump_file (DFI_loop2, decl);
3102 if (rtl_dump_file)
3103 dump_flow_info (rtl_dump_file);
3105 loops = loop_optimizer_init (rtl_dump_file);
3107 if (loops)
3109 /* The optimizations: */
3110 if (flag_unswitch_loops)
3111 unswitch_loops (loops);
3113 if (flag_peel_loops || flag_unroll_loops)
3114 unroll_and_peel_loops (loops,
3115 (flag_peel_loops ? UAP_PEEL : 0) |
3116 (flag_unroll_loops ? UAP_UNROLL : 0) |
3117 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3119 loop_optimizer_finalize (loops, rtl_dump_file);
3122 cleanup_cfg (CLEANUP_EXPENSIVE);
3123 delete_trivially_dead_insns (insns, max_reg_num ());
3124 reg_scan (insns, max_reg_num (), 0);
3125 if (rtl_dump_file)
3126 dump_flow_info (rtl_dump_file);
3127 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3128 timevar_pop (TV_LOOP);
3129 ggc_collect ();
3132 /* This is called from finish_function (within langhooks.parse_file)
3133 after each top-level definition is parsed.
3134 It is supposed to compile that function or variable
3135 and output the assembler code for it.
3136 After we return, the tree storage is freed. */
3138 void
3139 rest_of_compilation (tree decl)
3141 rtx insns;
3142 int rebuild_label_notes_after_reload;
3144 timevar_push (TV_REST_OF_COMPILATION);
3146 /* Register rtl specific functions for cfg. */
3147 rtl_register_cfg_hooks ();
3149 /* Now that we're out of the frontend, we shouldn't have any more
3150 CONCATs anywhere. */
3151 generating_concat_p = 0;
3153 /* When processing delayed functions, prepare_function_start() won't
3154 have been run to re-initialize it. */
3155 cse_not_expected = ! optimize;
3157 /* First, make sure that NOTE_BLOCK is set correctly for each
3158 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3159 if (!cfun->x_whole_function_mode_p)
3160 identify_blocks ();
3162 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3163 tree in sensible shape. So, we just recalculate it here. */
3164 if (cfun->x_whole_function_mode_p)
3165 reorder_blocks ();
3167 init_flow ();
3169 if (rest_of_handle_inlining (decl))
3170 goto exit_rest_of_compilation;
3172 /* If we're emitting a nested function, make sure its parent gets
3173 emitted as well. Doing otherwise confuses debug info. */
3175 tree parent;
3176 for (parent = DECL_CONTEXT (current_function_decl);
3177 parent != NULL_TREE;
3178 parent = get_containing_scope (parent))
3179 if (TREE_CODE (parent) == FUNCTION_DECL)
3180 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3183 /* We are now committed to emitting code for this function. Do any
3184 preparation, such as emitting abstract debug info for the inline
3185 before it gets mangled by optimization. */
3186 if (cgraph_function_possibly_inlined_p (decl))
3187 (*debug_hooks->outlining_inline_function) (decl);
3189 /* Remove any notes we don't need. That will make iterating
3190 over the instruction sequence faster, and allow the garbage
3191 collector to reclaim the memory used by the notes. */
3192 remove_unnecessary_notes ();
3193 reorder_blocks ();
3195 ggc_collect ();
3197 /* Initialize some variables used by the optimizers. */
3198 init_function_for_compilation ();
3200 if (! DECL_DEFER_OUTPUT (decl))
3201 TREE_ASM_WRITTEN (decl) = 1;
3203 /* Now that integrate will no longer see our rtl, we need not
3204 distinguish between the return value of this function and the
3205 return value of called functions. Also, we can remove all SETs
3206 of subregs of hard registers; they are only here because of
3207 integrate. Also, we can now initialize pseudos intended to
3208 carry magic hard reg data throughout the function. */
3209 rtx_equal_function_value_matters = 0;
3210 purge_hard_subreg_sets (get_insns ());
3212 /* Early return if there were errors. We can run afoul of our
3213 consistency checks, and there's not really much point in fixing them.
3214 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3215 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3216 || errorcount || sorrycount)
3217 goto exit_rest_of_compilation;
3219 timevar_push (TV_JUMP);
3220 open_dump_file (DFI_sibling, decl);
3221 insns = get_insns ();
3222 rebuild_jump_labels (insns);
3223 find_exception_handler_labels ();
3224 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3226 delete_unreachable_blocks ();
3228 /* We have to issue these warnings now already, because CFG cleanups
3229 further down may destroy the required information. */
3230 check_function_return_warnings ();
3232 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3233 if (flag_guess_branch_prob)
3235 timevar_push (TV_BRANCH_PROB);
3236 note_prediction_to_br_prob ();
3237 timevar_pop (TV_BRANCH_PROB);
3240 if (flag_optimize_sibling_calls)
3241 rest_of_handle_sibling_calls (insns);
3243 timevar_pop (TV_JUMP);
3245 insn_locators_initialize ();
3246 /* Complete generation of exception handling code. */
3247 if (doing_eh (0))
3249 timevar_push (TV_JUMP);
3250 open_dump_file (DFI_eh, decl);
3252 finish_eh_generation ();
3254 close_dump_file (DFI_eh, print_rtl, get_insns ());
3255 timevar_pop (TV_JUMP);
3258 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3259 generation, which might create new sets. */
3260 emit_initial_value_sets ();
3262 #ifdef FINALIZE_PIC
3263 /* If we are doing position-independent code generation, now
3264 is the time to output special prologues and epilogues.
3265 We do not want to do this earlier, because it just clutters
3266 up inline functions with meaningless insns. */
3267 if (flag_pic)
3268 FINALIZE_PIC;
3269 #endif
3271 insns = get_insns ();
3273 /* Copy any shared structure that should not be shared. */
3274 unshare_all_rtl (current_function_decl, insns);
3276 #ifdef SETJMP_VIA_SAVE_AREA
3277 /* This must be performed before virtual register instantiation.
3278 Please be aware the everything in the compiler that can look
3279 at the RTL up to this point must understand that REG_SAVE_AREA
3280 is just like a use of the REG contained inside. */
3281 if (current_function_calls_alloca)
3282 optimize_save_area_alloca (insns);
3283 #endif
3285 /* Instantiate all virtual registers. */
3286 instantiate_virtual_regs (current_function_decl, insns);
3288 open_dump_file (DFI_jump, decl);
3290 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3291 are initialized and to compute whether control can drop off the end
3292 of the function. */
3294 timevar_push (TV_JUMP);
3295 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3296 before jump optimization switches branch directions. */
3297 if (flag_guess_branch_prob)
3298 expected_value_to_br_prob ();
3300 reg_scan (insns, max_reg_num (), 0);
3301 rebuild_jump_labels (insns);
3302 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3303 delete_trivially_dead_insns (insns, max_reg_num ());
3304 if (rtl_dump_file)
3305 dump_flow_info (rtl_dump_file);
3306 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3307 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3309 if (optimize)
3311 free_bb_for_insn ();
3312 copy_loop_headers (insns);
3313 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3315 purge_line_number_notes (insns);
3317 timevar_pop (TV_JUMP);
3318 close_dump_file (DFI_jump, print_rtl, insns);
3320 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3321 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3322 goto exit_rest_of_compilation;
3324 /* Long term, this should probably move before the jump optimizer too,
3325 but I didn't want to disturb the rtl_dump_and_exit and related
3326 stuff at this time. */
3327 if (optimize > 0 && flag_ssa)
3328 insns = rest_of_handle_ssa (decl, insns);
3330 timevar_push (TV_JUMP);
3332 if (optimize)
3333 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3335 if (flag_delete_null_pointer_checks)
3336 rest_of_handle_null_pointer (decl, insns);
3338 /* Jump optimization, and the removal of NULL pointer checks, may
3339 have reduced the number of instructions substantially. CSE, and
3340 future passes, allocate arrays whose dimensions involve the
3341 maximum instruction UID, so if we can reduce the maximum UID
3342 we'll save big on memory. */
3343 renumber_insns (rtl_dump_file);
3344 timevar_pop (TV_JUMP);
3346 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3348 ggc_collect ();
3350 if (optimize > 0)
3351 rest_of_handle_cse (decl, insns);
3353 rest_of_handle_addressof (decl, insns);
3355 ggc_collect ();
3357 if (optimize > 0)
3359 if (flag_gcse)
3360 rest_of_handle_gcse (decl, insns);
3362 if (flag_loop_optimize)
3363 rest_of_handle_loop_optimize (decl, insns);
3365 if (flag_gcse)
3366 rest_of_handle_jump_bypass (decl, insns);
3369 timevar_push (TV_FLOW);
3371 rest_of_handle_cfg (decl, insns);
3373 if (optimize > 0
3374 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3376 rest_of_handle_branch_prob (decl, insns);
3378 if (flag_branch_probabilities
3379 && flag_profile_values
3380 && flag_value_profile_transformations)
3381 rest_of_handle_value_profile_transformations (decl, insns);
3383 /* Remove the death notes created for vpt. */
3384 if (flag_profile_values)
3385 count_or_remove_death_notes (NULL, 1);
3388 if (optimize > 0)
3389 rest_of_handle_if_conversion (decl, insns);
3391 if (flag_tracer)
3392 rest_of_handle_tracer (decl, insns);
3394 if (optimize > 0
3395 && (flag_unswitch_loops
3396 || flag_peel_loops
3397 || flag_unroll_loops))
3398 rest_of_handle_loop2 (decl, insns);
3400 if (flag_web)
3401 rest_of_handle_web (decl, insns);
3403 if (flag_rerun_cse_after_loop)
3404 rest_of_handle_cse2 (decl, insns);
3406 cse_not_expected = 1;
3408 rest_of_handle_life (decl, insns);
3410 if (optimize > 0)
3411 rest_of_handle_combine (decl, insns);
3413 if (flag_if_conversion)
3414 rest_of_handle_if_after_combine (decl, insns);
3416 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3417 rest_of_handle_regmove (decl, insns);
3419 /* Do unconditional splitting before register allocation to allow machine
3420 description to add extra information not needed previously. */
3421 split_all_insns (1);
3423 #ifdef OPTIMIZE_MODE_SWITCHING
3424 timevar_push (TV_MODE_SWITCH);
3426 no_new_pseudos = 0;
3427 optimize_mode_switching (NULL);
3428 no_new_pseudos = 1;
3430 timevar_pop (TV_MODE_SWITCH);
3431 #endif
3433 /* Any of the several passes since flow1 will have munged register
3434 lifetime data a bit. We need it to be up to date for scheduling
3435 (see handling of reg_known_equiv in init_alias_analysis). */
3436 recompute_reg_usage (insns, !optimize_size);
3438 #ifdef INSN_SCHEDULING
3439 rest_of_handle_sched (decl, insns);
3440 #endif
3442 /* Determine if the current function is a leaf before running reload
3443 since this can impact optimizations done by the prologue and
3444 epilogue thus changing register elimination offsets. */
3445 current_function_is_leaf = leaf_function_p ();
3447 timevar_push (TV_LOCAL_ALLOC);
3448 open_dump_file (DFI_lreg, decl);
3450 if (flag_new_regalloc)
3452 if (rest_of_handle_new_regalloc (decl, insns,
3453 &rebuild_label_notes_after_reload))
3454 goto exit_rest_of_compilation;
3456 else
3458 if (rest_of_handle_old_regalloc (decl, insns,
3459 &rebuild_label_notes_after_reload))
3460 goto exit_rest_of_compilation;
3463 ggc_collect ();
3465 open_dump_file (DFI_postreload, decl);
3467 /* Do a very simple CSE pass over just the hard registers. */
3468 if (optimize > 0)
3470 timevar_push (TV_RELOAD_CSE_REGS);
3471 reload_cse_regs (insns);
3472 timevar_pop (TV_RELOAD_CSE_REGS);
3475 /* Register allocation and reloading may have turned an indirect jump into
3476 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3477 jumping instructions. */
3478 if (rebuild_label_notes_after_reload)
3480 timevar_push (TV_JUMP);
3482 rebuild_jump_labels (insns);
3483 purge_all_dead_edges (0);
3485 timevar_pop (TV_JUMP);
3488 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3490 /* Re-create the death notes which were deleted during reload. */
3491 timevar_push (TV_FLOW2);
3492 open_dump_file (DFI_flow2, decl);
3494 #ifdef ENABLE_CHECKING
3495 verify_flow_info ();
3496 #endif
3498 /* If optimizing, then go ahead and split insns now. */
3499 #ifndef STACK_REGS
3500 if (optimize > 0)
3501 #endif
3502 split_all_insns (0);
3504 if (flag_branch_target_load_optimize)
3506 open_dump_file (DFI_branch_target_load, decl);
3508 branch_target_load_optimize (insns, false);
3510 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3512 ggc_collect ();
3515 if (optimize)
3516 cleanup_cfg (CLEANUP_EXPENSIVE);
3518 /* On some machines, the prologue and epilogue code, or parts thereof,
3519 can be represented as RTL. Doing so lets us schedule insns between
3520 it and the rest of the code and also allows delayed branch
3521 scheduling to operate in the epilogue. */
3522 thread_prologue_and_epilogue_insns (insns);
3523 epilogue_completed = 1;
3525 if (optimize)
3527 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3528 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3529 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3531 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3532 even for machines with possibly nonzero RETURN_POPS_ARGS
3533 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3534 push instructions will have popping returns. */
3535 #ifndef PUSH_ROUNDING
3536 if (!ACCUMULATE_OUTGOING_ARGS)
3537 #endif
3538 combine_stack_adjustments ();
3540 ggc_collect ();
3543 flow2_completed = 1;
3545 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3546 timevar_pop (TV_FLOW2);
3548 #ifdef HAVE_peephole2
3549 if (optimize > 0 && flag_peephole2)
3551 timevar_push (TV_PEEPHOLE2);
3552 open_dump_file (DFI_peephole2, decl);
3554 peephole2_optimize (rtl_dump_file);
3556 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3557 timevar_pop (TV_PEEPHOLE2);
3559 #endif
3561 if (optimize > 0)
3563 if (flag_rename_registers || flag_cprop_registers)
3564 rest_of_handle_regrename (decl, insns);
3566 rest_of_handle_reorder_blocks (decl, insns);
3569 if (flag_if_conversion2)
3571 timevar_push (TV_IFCVT2);
3572 open_dump_file (DFI_ce3, decl);
3574 if_convert (1);
3576 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3577 timevar_pop (TV_IFCVT2);
3580 if (flag_branch_target_load_optimize2)
3582 /* Leave this a warning for now so that it is possible to experiment
3583 with running this pass twice. In 3.6, we should either make this
3584 an error, or use separate dump files. */
3585 if (flag_branch_target_load_optimize)
3586 warning ("branch target register load optimization is not intended "
3587 "to be run twice");
3589 open_dump_file (DFI_branch_target_load, decl);
3591 branch_target_load_optimize (insns, true);
3593 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3595 ggc_collect ();
3598 #ifdef INSN_SCHEDULING
3599 if (optimize > 0 && flag_schedule_insns_after_reload)
3600 rest_of_handle_sched2 (decl, insns);
3601 #endif
3603 #ifdef LEAF_REGISTERS
3604 current_function_uses_only_leaf_regs
3605 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3606 #endif
3608 #ifdef STACK_REGS
3609 rest_of_handle_stack_regs (decl, insns);
3610 #endif
3612 compute_alignments ();
3614 /* CFG is no longer maintained up-to-date. */
3615 free_bb_for_insn ();
3617 if (targetm.machine_dependent_reorg != 0)
3618 rest_of_handle_machine_reorg (decl, insns);
3620 purge_line_number_notes (insns);
3621 cleanup_barriers ();
3623 #ifdef DELAY_SLOTS
3624 if (optimize > 0 && flag_delayed_branch)
3625 rest_of_handle_delay_slots (decl, insns);
3626 #endif
3628 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3629 timevar_push (TV_SHORTEN_BRANCH);
3630 split_all_insns_noflow ();
3631 timevar_pop (TV_SHORTEN_BRANCH);
3632 #endif
3634 convert_to_eh_region_ranges ();
3636 /* Shorten branches. */
3637 timevar_push (TV_SHORTEN_BRANCH);
3638 shorten_branches (get_insns ());
3639 timevar_pop (TV_SHORTEN_BRANCH);
3641 set_nothrow_function_flags ();
3642 if (current_function_nothrow)
3643 /* Now we know that this can't throw; set the flag for the benefit
3644 of other functions later in this translation unit. */
3645 TREE_NOTHROW (current_function_decl) = 1;
3647 rest_of_handle_final (decl, insns);
3649 /* Write DBX symbols if requested. */
3651 /* Note that for those inline functions where we don't initially
3652 know for certain that we will be generating an out-of-line copy,
3653 the first invocation of this routine (rest_of_compilation) will
3654 skip over this code by doing a `goto exit_rest_of_compilation;'.
3655 Later on, wrapup_global_declarations will (indirectly) call
3656 rest_of_compilation again for those inline functions that need
3657 to have out-of-line copies generated. During that call, we
3658 *will* be routed past here. */
3660 timevar_push (TV_SYMOUT);
3661 (*debug_hooks->function_decl) (decl);
3662 timevar_pop (TV_SYMOUT);
3664 exit_rest_of_compilation:
3666 coverage_end_function ();
3668 /* In case the function was not output,
3669 don't leave any temporary anonymous types
3670 queued up for sdb output. */
3671 #ifdef SDB_DEBUGGING_INFO
3672 if (write_symbols == SDB_DEBUG)
3673 sdbout_types (NULL_TREE);
3674 #endif
3676 reload_completed = 0;
3677 epilogue_completed = 0;
3678 flow2_completed = 0;
3679 no_new_pseudos = 0;
3681 timevar_push (TV_FINAL);
3683 /* Clear out the insn_length contents now that they are no
3684 longer valid. */
3685 init_insn_lengths ();
3687 /* Show no temporary slots allocated. */
3688 init_temp_slots ();
3690 free_basic_block_vars (0);
3691 free_bb_for_insn ();
3693 timevar_pop (TV_FINAL);
3695 if ((*targetm.binds_local_p) (current_function_decl))
3697 int pref = cfun->preferred_stack_boundary;
3698 if (cfun->recursive_call_emit
3699 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3700 pref = cfun->stack_alignment_needed;
3701 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3702 = pref;
3705 /* Make sure volatile mem refs aren't considered valid operands for
3706 arithmetic insns. We must call this here if this is a nested inline
3707 function, since the above code leaves us in the init_recog state
3708 (from final.c), and the function context push/pop code does not
3709 save/restore volatile_ok.
3711 ??? Maybe it isn't necessary for expand_start_function to call this
3712 anymore if we do it here? */
3714 init_recog_no_volatile ();
3716 /* We're done with this function. Free up memory if we can. */
3717 free_after_parsing (cfun);
3718 if (! DECL_DEFER_OUTPUT (decl))
3720 free_after_compilation (cfun);
3721 DECL_SAVED_INSNS (decl) = 0;
3723 cfun = 0;
3725 ggc_collect ();
3727 timevar_pop (TV_REST_OF_COMPILATION);
3730 /* Display help for target options. */
3731 void
3732 display_target_options (void)
3734 int undoc, i;
3735 static bool displayed = false;
3737 /* Avoid double printing for --help --target-help. */
3738 if (displayed)
3739 return;
3741 displayed = true;
3743 if (ARRAY_SIZE (target_switches) > 1
3744 #ifdef TARGET_OPTIONS
3745 || ARRAY_SIZE (target_options) > 1
3746 #endif
3749 int doc = 0;
3751 undoc = 0;
3753 printf (_("\nTarget specific options:\n"));
3755 for (i = ARRAY_SIZE (target_switches); i--;)
3757 const char *option = target_switches[i].name;
3758 const char *description = target_switches[i].description;
3760 if (option == NULL || *option == 0)
3761 continue;
3762 else if (description == NULL)
3764 undoc = 1;
3766 if (extra_warnings)
3767 printf (_(" -m%-23s [undocumented]\n"), option);
3769 else if (*description != 0)
3770 doc += printf (" -m%-23s %s\n", option, _(description));
3773 #ifdef TARGET_OPTIONS
3774 for (i = ARRAY_SIZE (target_options); i--;)
3776 const char *option = target_options[i].prefix;
3777 const char *description = target_options[i].description;
3779 if (option == NULL || *option == 0)
3780 continue;
3781 else if (description == NULL)
3783 undoc = 1;
3785 if (extra_warnings)
3786 printf (_(" -m%-23s [undocumented]\n"), option);
3788 else if (*description != 0)
3789 doc += printf (" -m%-23s %s\n", option, _(description));
3791 #endif
3792 if (undoc)
3794 if (doc)
3795 printf (_("\nThere are undocumented target specific options as well.\n"));
3796 else
3797 printf (_(" They exist, but they are not documented.\n"));
3802 /* Parse a -d... command line switch. */
3804 void
3805 decode_d_option (const char *arg)
3807 int i, c, matched;
3809 while (*arg)
3810 switch (c = *arg++)
3812 case 'a':
3813 for (i = 0; i < (int) DFI_MAX; ++i)
3814 dump_file[i].enabled = 1;
3815 break;
3816 case 'A':
3817 flag_debug_asm = 1;
3818 break;
3819 case 'p':
3820 flag_print_asm_name = 1;
3821 break;
3822 case 'P':
3823 flag_dump_rtl_in_asm = 1;
3824 flag_print_asm_name = 1;
3825 break;
3826 case 'v':
3827 graph_dump_format = vcg;
3828 break;
3829 case 'x':
3830 rtl_dump_and_exit = 1;
3831 break;
3832 case 'y':
3833 set_yydebug = 1;
3834 break;
3835 case 'D': /* These are handled by the preprocessor. */
3836 case 'I':
3837 break;
3838 case 'H':
3839 setup_core_dumping();
3840 break;
3842 default:
3843 matched = 0;
3844 for (i = 0; i < (int) DFI_MAX; ++i)
3845 if (c == dump_file[i].debug_switch)
3847 dump_file[i].enabled = 1;
3848 matched = 1;
3851 if (! matched)
3852 warning ("unrecognized gcc debugging option: %c", c);
3853 break;
3857 /* Indexed by enum debug_info_type. */
3858 const char *const debug_type_names[] =
3860 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3863 /* Decode -m switches. */
3864 /* Decode the switch -mNAME. */
3866 void
3867 set_target_switch (const char *name)
3869 size_t j;
3870 int valid_target_option = 0;
3872 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3873 if (!strcmp (target_switches[j].name, name))
3875 if (target_switches[j].value < 0)
3876 target_flags &= ~-target_switches[j].value;
3877 else
3878 target_flags |= target_switches[j].value;
3879 if (name[0] != 0)
3881 if (target_switches[j].value < 0)
3882 target_flags_explicit |= -target_switches[j].value;
3883 else
3884 target_flags_explicit |= target_switches[j].value;
3886 valid_target_option = 1;
3889 #ifdef TARGET_OPTIONS
3890 if (!valid_target_option)
3891 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3893 int len = strlen (target_options[j].prefix);
3894 if (target_options[j].value)
3896 if (!strcmp (target_options[j].prefix, name))
3898 *target_options[j].variable = target_options[j].value;
3899 valid_target_option = 1;
3902 else
3904 if (!strncmp (target_options[j].prefix, name, len))
3906 *target_options[j].variable = name + len;
3907 valid_target_option = 1;
3911 #endif
3913 if (!valid_target_option)
3914 error ("invalid option `%s'", name);
3917 /* Print version information to FILE.
3918 Each line begins with INDENT (for the case where FILE is the
3919 assembler output file). */
3921 void
3922 print_version (FILE *file, const char *indent)
3924 #ifndef __VERSION__
3925 #define __VERSION__ "[?]"
3926 #endif
3927 fnotice (file,
3928 #ifdef __GNUC__
3929 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3930 #else
3931 "%s%s%s version %s (%s) compiled by CC.\n"
3932 #endif
3933 , indent, *indent != 0 ? " " : "",
3934 lang_hooks.name, version_string, TARGET_NAME,
3935 indent, __VERSION__);
3936 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3937 indent, *indent != 0 ? " " : "",
3938 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3941 /* Print an option value and return the adjusted position in the line.
3942 ??? We don't handle error returns from fprintf (disk full); presumably
3943 other code will catch a disk full though. */
3945 static int
3946 print_single_switch (FILE *file, int pos, int max,
3947 const char *indent, const char *sep, const char *term,
3948 const char *type, const char *name)
3950 /* The ultrix fprintf returns 0 on success, so compute the result we want
3951 here since we need it for the following test. */
3952 int len = strlen (sep) + strlen (type) + strlen (name);
3954 if (pos != 0
3955 && pos + len > max)
3957 fprintf (file, "%s", term);
3958 pos = 0;
3960 if (pos == 0)
3962 fprintf (file, "%s", indent);
3963 pos = strlen (indent);
3965 fprintf (file, "%s%s%s", sep, type, name);
3966 pos += len;
3967 return pos;
3970 /* Print active target switches to FILE.
3971 POS is the current cursor position and MAX is the size of a "line".
3972 Each line begins with INDENT and ends with TERM.
3973 Each switch is separated from the next by SEP. */
3975 static void
3976 print_switch_values (FILE *file, int pos, int max,
3977 const char *indent, const char *sep, const char *term)
3979 size_t j;
3980 const char **p;
3982 /* Fill in the -frandom-seed option, if the user didn't pass it, so
3983 that it can be printed below. This helps reproducibility. */
3984 randomize ();
3986 /* Print the options as passed. */
3987 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
3988 _("options passed: "), "");
3990 for (p = &save_argv[1]; *p != NULL; p++)
3991 if (**p == '-')
3993 /* Ignore these. */
3994 if (strcmp (*p, "-o") == 0)
3996 if (p[1] != NULL)
3997 p++;
3998 continue;
4000 if (strcmp (*p, "-quiet") == 0)
4001 continue;
4002 if (strcmp (*p, "-version") == 0)
4003 continue;
4004 if ((*p)[1] == 'd')
4005 continue;
4007 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4009 if (pos > 0)
4010 fprintf (file, "%s", term);
4012 /* Print the -f and -m options that have been enabled.
4013 We don't handle language specific options but printing argv
4014 should suffice. */
4016 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4017 _("options enabled: "), "");
4019 for (j = 0; j < ARRAY_SIZE (f_options); j++)
4020 if (*f_options[j].variable == f_options[j].on_value)
4021 pos = print_single_switch (file, pos, max, indent, sep, term,
4022 "-f", f_options[j].string);
4024 /* Print target specific options. */
4026 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4027 if (target_switches[j].name[0] != '\0'
4028 && target_switches[j].value > 0
4029 && ((target_switches[j].value & target_flags)
4030 == target_switches[j].value))
4032 pos = print_single_switch (file, pos, max, indent, sep, term,
4033 "-m", target_switches[j].name);
4036 #ifdef TARGET_OPTIONS
4037 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4038 if (*target_options[j].variable != NULL)
4040 char prefix[256];
4041 sprintf (prefix, "-m%s", target_options[j].prefix);
4042 pos = print_single_switch (file, pos, max, indent, sep, term,
4043 prefix, *target_options[j].variable);
4045 #endif
4047 fprintf (file, "%s", term);
4050 /* Open assembly code output file. Do this even if -fsyntax-only is
4051 on, because then the driver will have provided the name of a
4052 temporary file or bit bucket for us. NAME is the file specified on
4053 the command line, possibly NULL. */
4054 static void
4055 init_asm_output (const char *name)
4057 if (name == NULL && asm_file_name == 0)
4058 asm_out_file = stdout;
4059 else
4061 if (asm_file_name == 0)
4063 int len = strlen (dump_base_name);
4064 char *dumpname = xmalloc (len + 6);
4065 memcpy (dumpname, dump_base_name, len + 1);
4066 strip_off_ending (dumpname, len);
4067 strcat (dumpname, ".s");
4068 asm_file_name = dumpname;
4070 if (!strcmp (asm_file_name, "-"))
4071 asm_out_file = stdout;
4072 else
4073 asm_out_file = fopen (asm_file_name, "w+");
4074 if (asm_out_file == 0)
4075 fatal_error ("can't open %s for writing: %m", asm_file_name);
4078 #ifdef IO_BUFFER_SIZE
4079 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
4080 _IOFBF, IO_BUFFER_SIZE);
4081 #endif
4083 if (!flag_syntax_only)
4085 targetm.asm_out.file_start ();
4087 #ifdef ASM_COMMENT_START
4088 if (flag_verbose_asm)
4090 /* Print the list of options in effect. */
4091 print_version (asm_out_file, ASM_COMMENT_START);
4092 print_switch_values (asm_out_file, 0, MAX_LINE,
4093 ASM_COMMENT_START, " ", "\n");
4094 /* Add a blank line here so it appears in assembler output but not
4095 screen output. */
4096 fprintf (asm_out_file, "\n");
4098 #endif
4102 /* Default version of get_pch_validity.
4103 By default, every flag difference is fatal; that will be mostly right for
4104 most targets, but completely right for very few. */
4106 void *
4107 default_get_pch_validity (size_t *len)
4109 #ifdef TARGET_OPTIONS
4110 size_t i;
4111 #endif
4112 char *result, *r;
4114 *len = sizeof (target_flags) + 2;
4115 #ifdef TARGET_OPTIONS
4116 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4118 *len += 1;
4119 if (*target_options[i].variable)
4120 *len += strlen (*target_options[i].variable);
4122 #endif
4124 result = r = xmalloc (*len);
4125 r[0] = flag_pic;
4126 r[1] = flag_pie;
4127 r += 2;
4128 memcpy (r, &target_flags, sizeof (target_flags));
4129 r += sizeof (target_flags);
4131 #ifdef TARGET_OPTIONS
4132 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4134 const char *str = *target_options[i].variable;
4135 size_t l;
4136 if (! str)
4137 str = "";
4138 l = strlen (str) + 1;
4139 memcpy (r, str, l);
4140 r += l;
4142 #endif
4144 return result;
4147 /* Default version of pch_valid_p. */
4149 const char *
4150 default_pch_valid_p (const void *data_p, size_t len)
4152 const char *data = (const char *)data_p;
4153 const char *flag_that_differs = NULL;
4154 size_t i;
4156 /* -fpic and -fpie also usually make a PCH invalid. */
4157 if (data[0] != flag_pic)
4158 return _("created and used with different settings of -fpic");
4159 if (data[1] != flag_pie)
4160 return _("created and used with different settings of -fpie");
4161 data += 2;
4163 /* Check target_flags. */
4164 if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
4166 for (i = 0; i < ARRAY_SIZE (target_switches); i++)
4168 int bits;
4169 int tf;
4171 memcpy (&tf, data, sizeof (target_flags));
4173 bits = target_switches[i].value;
4174 if (bits < 0)
4175 bits = -bits;
4176 if ((target_flags & bits) != (tf & bits))
4178 flag_that_differs = target_switches[i].name;
4179 goto make_message;
4182 abort ();
4184 data += sizeof (target_flags);
4185 len -= sizeof (target_flags);
4187 /* Check string options. */
4188 #ifdef TARGET_OPTIONS
4189 for (i = 0; i < ARRAY_SIZE (target_options); i++)
4191 const char *str = *target_options[i].variable;
4192 size_t l;
4193 if (! str)
4194 str = "";
4195 l = strlen (str) + 1;
4196 if (len < l || memcmp (data, str, l) != 0)
4198 flag_that_differs = target_options[i].prefix;
4199 goto make_message;
4201 data += l;
4202 len -= l;
4204 #endif
4206 return NULL;
4208 make_message:
4210 char *r;
4211 asprintf (&r, _("created and used with differing settings of `-m%s'"),
4212 flag_that_differs);
4213 if (r == NULL)
4214 return _("out of memory");
4215 return r;
4219 /* Default tree printer. Handles declarations only. */
4220 static bool
4221 default_tree_printer (pretty_printer * pp, text_info *text)
4223 switch (*text->format_spec)
4225 case 'D':
4226 case 'F':
4227 case 'T':
4229 tree t = va_arg (*text->args_ptr, tree);
4230 const char *n = DECL_NAME (t)
4231 ? (*lang_hooks.decl_printable_name) (t, 2)
4232 : "<anonymous>";
4233 pp_string (pp, n);
4235 return true;
4237 default:
4238 return false;
4242 /* Initialization of the front end environment, before command line
4243 options are parsed. Signal handlers, internationalization etc.
4244 ARGV0 is main's argv[0]. */
4245 static void
4246 general_init (const char *argv0)
4248 const char *p;
4250 p = argv0 + strlen (argv0);
4251 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4252 --p;
4253 progname = p;
4255 xmalloc_set_program_name (progname);
4257 hex_init ();
4259 gcc_init_libintl ();
4261 /* Initialize the diagnostics reporting machinery, so option parsing
4262 can give warnings and errors. */
4263 diagnostic_initialize (global_dc);
4264 /* Set a default printer. Language specific initializations will
4265 override it later. */
4266 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4268 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4269 #ifdef SIGSEGV
4270 signal (SIGSEGV, crash_signal);
4271 #endif
4272 #ifdef SIGILL
4273 signal (SIGILL, crash_signal);
4274 #endif
4275 #ifdef SIGBUS
4276 signal (SIGBUS, crash_signal);
4277 #endif
4278 #ifdef SIGABRT
4279 signal (SIGABRT, crash_signal);
4280 #endif
4281 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4282 signal (SIGIOT, crash_signal);
4283 #endif
4284 #ifdef SIGFPE
4285 signal (SIGFPE, crash_signal);
4286 #endif
4288 /* Other host-specific signal setup. */
4289 (*host_hooks.extra_signals)();
4291 /* Initialize the garbage-collector, string pools and tree type hash
4292 table. */
4293 init_ggc ();
4294 init_stringpool ();
4295 init_ttree ();
4297 /* Initialize register usage now so switches may override. */
4298 init_reg_sets ();
4300 /* Register the language-independent parameters. */
4301 add_params (lang_independent_params, LAST_PARAM);
4303 /* This must be done after add_params but before argument processing. */
4304 init_ggc_heuristics();
4307 /* Process the options that have been parsed. */
4308 static void
4309 process_options (void)
4311 /* Allow the front end to perform consistency checks and do further
4312 initialization based on the command line options. This hook also
4313 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4314 so we can correctly initialize debug output. */
4315 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4316 input_filename = main_input_filename;
4318 #ifdef OVERRIDE_OPTIONS
4319 /* Some machines may reject certain combinations of options. */
4320 OVERRIDE_OPTIONS;
4321 #endif
4323 /* Set aux_base_name if not already set. */
4324 if (aux_base_name)
4326 else if (main_input_filename)
4328 char *name = xstrdup (lbasename (main_input_filename));
4330 strip_off_ending (name, strlen (name));
4331 aux_base_name = name;
4333 else
4334 aux_base_name = "gccaux";
4336 /* Set up the align_*_log variables, defaulting them to 1 if they
4337 were still unset. */
4338 if (align_loops <= 0) align_loops = 1;
4339 if (align_loops_max_skip > align_loops || !align_loops)
4340 align_loops_max_skip = align_loops - 1;
4341 align_loops_log = floor_log2 (align_loops * 2 - 1);
4342 if (align_jumps <= 0) align_jumps = 1;
4343 if (align_jumps_max_skip > align_jumps || !align_jumps)
4344 align_jumps_max_skip = align_jumps - 1;
4345 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4346 if (align_labels <= 0) align_labels = 1;
4347 align_labels_log = floor_log2 (align_labels * 2 - 1);
4348 if (align_labels_max_skip > align_labels || !align_labels)
4349 align_labels_max_skip = align_labels - 1;
4350 if (align_functions <= 0) align_functions = 1;
4351 align_functions_log = floor_log2 (align_functions * 2 - 1);
4353 /* Unrolling all loops implies that standard loop unrolling must also
4354 be done. */
4355 if (flag_unroll_all_loops)
4356 flag_unroll_loops = 1;
4358 if (flag_unroll_loops)
4360 flag_old_unroll_loops = 0;
4361 flag_old_unroll_all_loops = 0;
4364 if (flag_old_unroll_all_loops)
4365 flag_old_unroll_loops = 1;
4367 /* Old loop unrolling requires that strength_reduction be on also. Silently
4368 turn on strength reduction here if it isn't already on. Also, the loop
4369 unrolling code assumes that cse will be run after loop, so that must
4370 be turned on also. */
4371 if (flag_old_unroll_loops)
4373 flag_strength_reduce = 1;
4374 flag_rerun_cse_after_loop = 1;
4376 if (flag_unroll_loops || flag_peel_loops)
4377 flag_rerun_cse_after_loop = 1;
4379 if (flag_non_call_exceptions)
4380 flag_asynchronous_unwind_tables = 1;
4381 if (flag_asynchronous_unwind_tables)
4382 flag_unwind_tables = 1;
4384 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4385 interface. */
4386 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4387 flag_unit_at_a_time = 0;
4389 if (flag_value_profile_transformations)
4390 flag_profile_values = 1;
4392 /* Warn about options that are not supported on this machine. */
4393 #ifndef INSN_SCHEDULING
4394 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4395 warning ("instruction scheduling not supported on this target machine");
4396 #endif
4397 #ifndef DELAY_SLOTS
4398 if (flag_delayed_branch)
4399 warning ("this target machine does not have delayed branches");
4400 #endif
4402 user_label_prefix = USER_LABEL_PREFIX;
4403 if (flag_leading_underscore != -1)
4405 /* If the default prefix is more complicated than "" or "_",
4406 issue a warning and ignore this option. */
4407 if (user_label_prefix[0] == 0 ||
4408 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4410 user_label_prefix = flag_leading_underscore ? "_" : "";
4412 else
4413 warning ("-f%sleading-underscore not supported on this target machine",
4414 flag_leading_underscore ? "" : "no-");
4417 /* If we are in verbose mode, write out the version and maybe all the
4418 option flags in use. */
4419 if (version_flag)
4421 print_version (stderr, "");
4422 if (! quiet_flag)
4423 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4426 if (flag_syntax_only)
4428 write_symbols = NO_DEBUG;
4429 profile_flag = 0;
4432 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
4433 level is 0. */
4434 if (debug_info_level == DINFO_LEVEL_NONE)
4435 write_symbols = NO_DEBUG;
4437 /* Now we know write_symbols, set up the debug hooks based on it.
4438 By default we do nothing for debug output. */
4439 if (write_symbols == NO_DEBUG)
4440 debug_hooks = &do_nothing_debug_hooks;
4441 #if defined(DBX_DEBUGGING_INFO)
4442 else if (write_symbols == DBX_DEBUG)
4443 debug_hooks = &dbx_debug_hooks;
4444 #endif
4445 #if defined(XCOFF_DEBUGGING_INFO)
4446 else if (write_symbols == XCOFF_DEBUG)
4447 debug_hooks = &xcoff_debug_hooks;
4448 #endif
4449 #ifdef SDB_DEBUGGING_INFO
4450 else if (write_symbols == SDB_DEBUG)
4451 debug_hooks = &sdb_debug_hooks;
4452 #endif
4453 #ifdef DWARF_DEBUGGING_INFO
4454 else if (write_symbols == DWARF_DEBUG)
4455 debug_hooks = &dwarf_debug_hooks;
4456 #endif
4457 #ifdef DWARF2_DEBUGGING_INFO
4458 else if (write_symbols == DWARF2_DEBUG)
4459 debug_hooks = &dwarf2_debug_hooks;
4460 #endif
4461 #ifdef VMS_DEBUGGING_INFO
4462 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4463 debug_hooks = &vmsdbg_debug_hooks;
4464 #endif
4465 else
4466 error ("target system does not support the \"%s\" debug format",
4467 debug_type_names[write_symbols]);
4469 /* If auxiliary info generation is desired, open the output file.
4470 This goes in the same directory as the source file--unlike
4471 all the other output files. */
4472 if (flag_gen_aux_info)
4474 aux_info_file = fopen (aux_info_file_name, "w");
4475 if (aux_info_file == 0)
4476 fatal_error ("can't open %s: %m", aux_info_file_name);
4479 if (! targetm.have_named_sections)
4481 if (flag_function_sections)
4483 warning ("-ffunction-sections not supported for this target");
4484 flag_function_sections = 0;
4486 if (flag_data_sections)
4488 warning ("-fdata-sections not supported for this target");
4489 flag_data_sections = 0;
4493 if (flag_function_sections && profile_flag)
4495 warning ("-ffunction-sections disabled; it makes profiling impossible");
4496 flag_function_sections = 0;
4499 #ifndef HAVE_prefetch
4500 if (flag_prefetch_loop_arrays)
4502 warning ("-fprefetch-loop-arrays not supported for this target");
4503 flag_prefetch_loop_arrays = 0;
4505 #else
4506 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4508 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4509 flag_prefetch_loop_arrays = 0;
4511 #endif
4513 /* This combination of options isn't handled for i386 targets and doesn't
4514 make much sense anyway, so don't allow it. */
4515 if (flag_prefetch_loop_arrays && optimize_size)
4517 warning ("-fprefetch-loop-arrays is not supported with -Os");
4518 flag_prefetch_loop_arrays = 0;
4521 #ifndef OBJECT_FORMAT_ELF
4522 if (flag_function_sections && write_symbols != NO_DEBUG)
4523 warning ("-ffunction-sections may affect debugging on some targets");
4524 #endif
4526 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4527 if (flag_signaling_nans)
4528 flag_trapping_math = 1;
4531 /* Initialize the compiler back end. */
4532 static void
4533 backend_init (void)
4535 init_adjust_machine_modes ();
4537 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4538 || debug_info_level == DINFO_LEVEL_VERBOSE
4539 #ifdef VMS_DEBUGGING_INFO
4540 /* Enable line number info for traceback. */
4541 || debug_info_level > DINFO_LEVEL_NONE
4542 #endif
4543 || flag_test_coverage
4544 || warn_notreached);
4546 init_regs ();
4547 init_fake_stack_mems ();
4548 init_alias_once ();
4549 init_loop ();
4550 init_reload ();
4551 init_function_once ();
4552 init_varasm_once ();
4554 /* The following initialization functions need to generate rtl, so
4555 provide a dummy function context for them. */
4556 init_dummy_function_start ();
4557 init_expmed ();
4558 if (flag_caller_saves)
4559 init_caller_save ();
4560 expand_dummy_function_end ();
4563 /* Language-dependent initialization. Returns nonzero on success. */
4564 static int
4565 lang_dependent_init (const char *name)
4567 if (dump_base_name == 0)
4568 dump_base_name = name ? name : "gccdump";
4570 /* Other front-end initialization. */
4571 if ((*lang_hooks.init) () == 0)
4572 return 0;
4574 init_asm_output (name);
4576 /* These create various _DECL nodes, so need to be called after the
4577 front end is initialized. */
4578 init_eh ();
4579 init_optabs ();
4581 /* The following initialization functions need to generate rtl, so
4582 provide a dummy function context for them. */
4583 init_dummy_function_start ();
4584 init_expr_once ();
4585 expand_dummy_function_end ();
4587 /* If dbx symbol table desired, initialize writing it and output the
4588 predefined types. */
4589 timevar_push (TV_SYMOUT);
4591 #ifdef DWARF2_UNWIND_INFO
4592 if (dwarf2out_do_frame ())
4593 dwarf2out_frame_init ();
4594 #endif
4596 /* Now we have the correct original filename, we can initialize
4597 debug output. */
4598 (*debug_hooks->init) (name);
4600 timevar_pop (TV_SYMOUT);
4602 return 1;
4605 /* Clean up: close opened files, etc. */
4607 static void
4608 finalize (void)
4610 /* Close the dump files. */
4611 if (flag_gen_aux_info)
4613 fclose (aux_info_file);
4614 if (errorcount)
4615 unlink (aux_info_file_name);
4618 /* Close non-debugging input and output files. Take special care to note
4619 whether fclose returns an error, since the pages might still be on the
4620 buffer chain while the file is open. */
4622 if (asm_out_file)
4624 if (ferror (asm_out_file) != 0)
4625 fatal_error ("error writing to %s: %m", asm_file_name);
4626 if (fclose (asm_out_file) != 0)
4627 fatal_error ("error closing %s: %m", asm_file_name);
4630 /* Do whatever is necessary to finish printing the graphs. */
4631 if (graph_dump_format != no_graph)
4633 int i;
4635 for (i = 0; i < (int) DFI_MAX; ++i)
4636 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4638 char seq[16];
4639 char *suffix;
4641 sprintf (seq, DUMPFILE_FORMAT, i);
4642 suffix = concat (seq, dump_file[i].extension, NULL);
4643 finish_graph_dump_file (dump_base_name, suffix);
4644 free (suffix);
4648 if (mem_report)
4650 ggc_print_statistics ();
4651 stringpool_statistics ();
4652 dump_tree_statistics ();
4655 /* Free up memory for the benefit of leak detectors. */
4656 free_reg_info ();
4658 /* Language-specific end of compilation actions. */
4659 (*lang_hooks.finish) ();
4662 /* Initialize the compiler, and compile the input file. */
4663 static void
4664 do_compile (void)
4666 /* Initialize timing first. The C front ends read the main file in
4667 the post_options hook, and C++ does file timings. */
4668 if (time_report || !quiet_flag || flag_detailed_statistics)
4669 timevar_init ();
4670 timevar_start (TV_TOTAL);
4672 process_options ();
4674 /* Don't do any more if an error has already occurred. */
4675 if (!errorcount)
4677 /* Set up the back-end if requested. */
4678 if (!no_backend)
4679 backend_init ();
4681 /* Language-dependent initialization. Returns true on success. */
4682 if (lang_dependent_init (main_input_filename))
4684 if (flag_unit_at_a_time)
4686 open_dump_file (DFI_cgraph, NULL);
4687 cgraph_dump_file = rtl_dump_file;
4688 rtl_dump_file = NULL;
4691 compile_file ();
4693 if (flag_unit_at_a_time)
4695 rtl_dump_file = cgraph_dump_file;
4696 cgraph_dump_file = NULL;
4697 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4701 finalize ();
4704 /* Stop timing and print the times. */
4705 timevar_stop (TV_TOTAL);
4706 timevar_print (stderr);
4709 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4710 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4711 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4713 It is not safe to call this function more than once. */
4716 toplev_main (unsigned int argc, const char **argv)
4718 save_argv = argv;
4720 /* Initialization of GCC's environment, and diagnostics. */
4721 general_init (argv[0]);
4723 /* Parse the options and do minimal processing; basically just
4724 enough to default flags appropriately. */
4725 decode_options (argc, argv);
4727 randomize ();
4729 /* Exit early if we can (e.g. -help). */
4730 if (!exit_after_options)
4731 do_compile ();
4733 if (errorcount || sorrycount)
4734 return (FATAL_EXIT_CODE);
4736 return (SUCCESS_EXIT_CODE);