* c.opt: Introduce -fworking-directory.
[official-gcc.git] / gcc / toplev.c
blob73d459ac5bf4d4c5efaf9753e33036e2d75d3b9a
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"
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
84 #endif
86 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
87 #include "dbxout.h"
88 #endif
90 #ifdef SDB_DEBUGGING_INFO
91 #include "sdbout.h"
92 #endif
94 #ifdef XCOFF_DEBUGGING_INFO
95 #include "xcoffout.h" /* Needed for external data
96 declarations for e.g. AIX 4.x. */
97 #endif
99 /* Carry information from ASM_DECLARE_OBJECT_NAME
100 to ASM_FINISH_DECLARE_OBJECT. */
102 extern int size_directive_output;
103 extern tree last_assemble_variable_decl;
105 extern void reg_alloc (void);
107 static void general_init (const char *);
108 static void do_compile (void);
109 static void process_options (void);
110 static void backend_init (void);
111 static int lang_dependent_init (const char *);
112 static void init_asm_output (const char *);
113 static void finalize (void);
115 static void crash_signal (int) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
119 static int print_single_switch (FILE *, int, int, const char *,
120 const char *, const char *,
121 const char *, const char *);
122 static void print_switch_values (FILE *, int, int, const char *,
123 const char *, const char *);
125 /* Rest of compilation helper functions. */
126 static bool rest_of_handle_inlining (tree);
127 static rtx rest_of_handle_ssa (tree, rtx);
128 static void rest_of_handle_cse (tree, rtx);
129 static void rest_of_handle_cse2 (tree, rtx);
130 static void rest_of_handle_gcse (tree, rtx);
131 static void rest_of_handle_life (tree, rtx);
132 static void rest_of_handle_loop_optimize (tree, rtx);
133 static void rest_of_handle_loop2 (tree, rtx);
134 static void rest_of_handle_jump_bypass (tree, rtx);
135 static void rest_of_handle_sibling_calls (rtx);
136 static void rest_of_handle_null_pointer (tree, rtx);
137 static void rest_of_handle_addressof (tree, rtx);
138 static void rest_of_handle_cfg (tree, rtx);
139 static void rest_of_handle_branch_prob (tree, rtx);
140 static void rest_of_handle_if_conversion (tree, rtx);
141 static void rest_of_handle_if_after_combine (tree, rtx);
142 static void rest_of_handle_tracer (tree, rtx);
143 static void rest_of_handle_combine (tree, rtx);
144 static void rest_of_handle_regmove (tree, rtx);
145 #ifdef INSN_SCHEDULING
146 static void rest_of_handle_sched (tree, rtx);
147 static void rest_of_handle_sched2 (tree, rtx);
148 #endif
149 static bool rest_of_handle_new_regalloc (tree, rtx, int *);
150 static bool rest_of_handle_old_regalloc (tree, rtx, int *);
151 static void rest_of_handle_regrename (tree, rtx);
152 static void rest_of_handle_reorder_blocks (tree, rtx);
153 #ifdef STACK_REGS
154 static void rest_of_handle_stack_regs (tree, rtx);
155 #endif
156 static void rest_of_handle_machine_reorg (tree, rtx);
157 #ifdef DELAY_SLOTS
158 static void rest_of_handle_delay_slots (tree, rtx);
159 #endif
160 static void rest_of_handle_final (tree, rtx);
162 /* Nonzero to dump debug info whilst parsing (-dy option). */
163 static int set_yydebug;
165 /* True if we don't need a backend (e.g. preprocessing only). */
166 static bool no_backend;
168 /* Length of line when printing switch values. */
169 #define MAX_LINE 75
171 /* Name of program invoked, sans directories. */
173 const char *progname;
175 /* Copy of argument vector to toplev_main. */
176 static const char **save_argv;
178 /* Name of top-level original source file (what was input to cpp).
179 This comes from the #-command at the beginning of the actual input.
180 If there isn't any there, then this is the cc1 input file name. */
182 const char *main_input_filename;
184 /* Current position in real source file. */
186 location_t input_location;
188 /* Nonzero if it is unsafe to create any new pseudo registers. */
189 int no_new_pseudos;
191 /* Stack of currently pending input files. */
193 struct file_stack *input_file_stack;
195 /* Incremented on each change to input_file_stack. */
196 int input_file_stack_tick;
198 /* Name to use as base of names for dump output files. */
200 const char *dump_base_name;
202 /* Name to use as a base for auxiliary output files. */
204 const char *aux_base_name;
206 /* Format to use to print dumpfile index value */
207 #ifndef DUMPFILE_FORMAT
208 #define DUMPFILE_FORMAT ".%02d."
209 #endif
211 /* Bit flags that specify the machine subtype we are compiling for.
212 Bits are tested using macros TARGET_... defined in the tm.h file
213 and set by `-m...' switches. Must be defined in rtlanal.c. */
215 extern int target_flags;
217 /* A mask of target_flags that includes bit X if X was set or cleared
218 on the command line. */
220 int target_flags_explicit;
222 /* Debug hooks - dependent upon command line options. */
224 const struct gcc_debug_hooks *debug_hooks = &do_nothing_debug_hooks;
226 /* Describes a dump file. */
228 struct dump_file_info
230 /* The unique extension to apply, e.g. ".jump". */
231 const char *const extension;
233 /* The -d<c> character that enables this dump file. */
234 char const debug_switch;
236 /* True if there is a corresponding graph dump file. */
237 char const graph_dump_p;
239 /* True if the user selected this dump. */
240 char enabled;
242 /* True if the files have been initialized (ie truncated). */
243 char initialized;
246 /* Enumerate the extant dump files. */
248 enum dump_file_index
250 DFI_cgraph,
251 DFI_rtl,
252 DFI_sibling,
253 DFI_eh,
254 DFI_jump,
255 DFI_ssa,
256 DFI_ssa_ccp,
257 DFI_ssa_dce,
258 DFI_ussa,
259 DFI_null,
260 DFI_cse,
261 DFI_addressof,
262 DFI_gcse,
263 DFI_loop,
264 DFI_bypass,
265 DFI_cfg,
266 DFI_bp,
267 DFI_ce1,
268 DFI_tracer,
269 DFI_loop2,
270 DFI_cse2,
271 DFI_life,
272 DFI_combine,
273 DFI_ce2,
274 DFI_regmove,
275 DFI_sched,
276 DFI_lreg,
277 DFI_greg,
278 DFI_postreload,
279 DFI_flow2,
280 DFI_peephole2,
281 DFI_rnreg,
282 DFI_bbro,
283 DFI_ce3,
284 DFI_branch_target_load,
285 DFI_sched2,
286 DFI_stack,
287 DFI_mach,
288 DFI_dbr,
289 DFI_MAX
292 /* Describes all the dump files. Should be kept in order of the
293 pass and in sync with dump_file_index above.
295 Remaining -d letters:
297 " m q "
298 " JK O Q V YZ"
301 static struct dump_file_info dump_file[DFI_MAX] =
303 { "cgraph", 'U', 0, 0, 0 },
304 { "rtl", 'r', 0, 0, 0 },
305 { "sibling", 'i', 0, 0, 0 },
306 { "eh", 'h', 0, 0, 0 },
307 { "jump", 'j', 0, 0, 0 },
308 { "ssa", 'e', 1, 0, 0 },
309 { "ssaccp", 'W', 1, 0, 0 },
310 { "ssadce", 'X', 1, 0, 0 },
311 { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */
312 { "null", 'u', 0, 0, 0 },
313 { "cse", 's', 0, 0, 0 },
314 { "addressof", 'F', 0, 0, 0 },
315 { "gcse", 'G', 1, 0, 0 },
316 { "loop", 'L', 1, 0, 0 },
317 { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */
318 { "cfg", 'f', 1, 0, 0 },
319 { "bp", 'b', 1, 0, 0 },
320 { "ce1", 'C', 1, 0, 0 },
321 { "tracer", 'T', 1, 0, 0 },
322 { "loop2", 'L', 1, 0, 0 },
323 { "cse2", 't', 1, 0, 0 },
324 { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */
325 { "combine", 'c', 1, 0, 0 },
326 { "ce2", 'C', 1, 0, 0 },
327 { "regmove", 'N', 1, 0, 0 },
328 { "sched", 'S', 1, 0, 0 },
329 { "lreg", 'l', 1, 0, 0 },
330 { "greg", 'g', 1, 0, 0 },
331 { "postreload", 'o', 1, 0, 0 },
332 { "flow2", 'w', 1, 0, 0 },
333 { "peephole2", 'z', 1, 0, 0 },
334 { "rnreg", 'n', 1, 0, 0 },
335 { "bbro", 'B', 1, 0, 0 },
336 { "ce3", 'E', 1, 0, 0 },
337 { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */
338 { "sched2", 'R', 1, 0, 0 },
339 { "stack", 'k', 1, 0, 0 },
340 { "mach", 'M', 1, 0, 0 },
341 { "dbr", 'd', 0, 0, 0 },
344 static int open_dump_file (enum dump_file_index, tree);
345 static void close_dump_file (enum dump_file_index,
346 void (*) (FILE *, rtx), rtx);
348 /* Other flags saying which kinds of debugging dump have been requested. */
350 int rtl_dump_and_exit;
351 int flag_print_asm_name;
352 enum graph_dump_types graph_dump_format;
354 /* Name for output file of assembly code, specified with -o. */
356 const char *asm_file_name;
358 /* Type(s) of debugging information we are producing (if any).
359 See flags.h for the definitions of the different possible
360 types of debugging information. */
361 enum debug_info_type write_symbols = NO_DEBUG;
363 /* Level of debugging information we are producing. See flags.h
364 for the definitions of the different possible levels. */
365 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
367 /* Nonzero means use GNU-only extensions in the generated symbolic
368 debugging information. */
369 /* Currently, this only has an effect when write_symbols is set to
370 DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
371 int use_gnu_debug_info_extensions = 0;
373 /* Nonzero means do optimizations. -O.
374 Particular numeric values stand for particular amounts of optimization;
375 thus, -O2 stores 2 here. However, the optimizations beyond the basic
376 ones are not controlled directly by this variable. Instead, they are
377 controlled by individual `flag_...' variables that are defaulted
378 based on this variable. */
380 int optimize = 0;
382 /* Nonzero means optimize for size. -Os.
383 The only valid values are zero and nonzero. When optimize_size is
384 nonzero, optimize defaults to 2, but certain individual code
385 bloating optimizations are disabled. */
387 int optimize_size = 0;
389 /* The FUNCTION_DECL for the function currently being compiled,
390 or 0 if between functions. */
391 tree current_function_decl;
393 /* Set to the FUNC_BEGIN label of the current function, or NULL_TREE
394 if none. */
395 tree current_function_func_begin_label;
397 /* Nonzero if doing dwarf2 duplicate elimination. */
399 int flag_eliminate_dwarf2_dups = 0;
401 /* Nonzero if doing unused type elimination. */
403 int flag_eliminate_unused_debug_types = 1;
405 /* Nonzero means emit debugging information only for symbols which are used. */
406 int flag_debug_only_used_symbols = 0;
408 /* Nonzero if generating code to do profiling. */
410 int profile_flag = 0;
412 /* Nonzero if generating code to profile program flow graph arcs. */
414 int profile_arc_flag = 0;
416 /* Nonzero if value histograms should be measured. */
418 int flag_profile_values = 0;
420 /* Nonzero if generating info for gcov to calculate line test coverage. */
422 int flag_test_coverage = 0;
424 /* Nonzero indicates that branch taken probabilities should be calculated. */
426 int flag_branch_probabilities = 0;
428 /* Nonzero if basic blocks should be reordered. */
430 int flag_reorder_blocks = 0;
432 /* Nonzero if functions should be reordered. */
434 int flag_reorder_functions = 0;
436 /* Nonzero if registers should be renamed. */
438 int flag_rename_registers = 0;
439 int flag_cprop_registers = 0;
441 /* Nonzero for -pedantic switch: warn about anything
442 that standard spec forbids. */
444 int pedantic = 0;
446 /* Temporarily suppress certain warnings.
447 This is set while reading code from a system header file. */
449 int in_system_header = 0;
451 /* Don't print functions as they are compiled. -quiet. */
453 int quiet_flag = 0;
455 /* Print times taken by the various passes. -ftime-report. */
457 int time_report = 0;
459 /* Print memory still in use at end of compilation (which may have little
460 to do with peak memory consumption). -fmem-report. */
462 int mem_report = 0;
464 /* Nonzero means to collect statistics which might be expensive
465 and to print them when we are done. */
466 int flag_detailed_statistics = 0;
468 /* A random sequence of characters, unless overridden by user. */
469 const char *flag_random_seed;
471 /* A local time stamp derived from the time of compilation. It will be
472 zero if the system cannot provide a time. It will be -1u, if the
473 user has specified a particular random seed. */
474 unsigned local_tick;
476 /* -f flags. */
478 /* Nonzero means `char' should be signed. */
480 int flag_signed_char;
482 /* Nonzero means give an enum type only as many bytes as it needs. */
484 int flag_short_enums;
486 /* Nonzero for -fcaller-saves: allocate values in regs that need to
487 be saved across function calls, if that produces overall better code.
488 Optional now, so people can test it. */
490 #ifdef DEFAULT_CALLER_SAVES
491 int flag_caller_saves = 1;
492 #else
493 int flag_caller_saves = 0;
494 #endif
496 /* Nonzero if structures and unions should be returned in memory.
498 This should only be defined if compatibility with another compiler or
499 with an ABI is needed, because it results in slower code. */
501 #ifndef DEFAULT_PCC_STRUCT_RETURN
502 #define DEFAULT_PCC_STRUCT_RETURN 1
503 #endif
505 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
507 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
509 /* Nonzero for -fforce-mem: load memory value into a register
510 before arithmetic on it. This makes better cse but slower compilation. */
512 int flag_force_mem = 0;
514 /* Nonzero for -fforce-addr: load memory address into a register before
515 reference to memory. This makes better cse but slower compilation. */
517 int flag_force_addr = 0;
519 /* Nonzero for -fdefer-pop: don't pop args after each function call;
520 instead save them up to pop many calls' args with one insns. */
522 int flag_defer_pop = 0;
524 /* Nonzero for -ffloat-store: don't allocate floats and doubles
525 in extended-precision registers. */
527 int flag_float_store = 0;
529 /* Nonzero for -fcse-follow-jumps:
530 have cse follow jumps to do a more extensive job. */
532 int flag_cse_follow_jumps;
534 /* Nonzero for -fcse-skip-blocks:
535 have cse follow a branch around a block. */
536 int flag_cse_skip_blocks;
538 /* Nonzero for -fexpensive-optimizations:
539 perform miscellaneous relatively-expensive optimizations. */
540 int flag_expensive_optimizations;
542 /* Nonzero for -fthread-jumps:
543 have jump optimize output of loop. */
545 int flag_thread_jumps;
547 /* Nonzero enables strength-reduction in loop.c. */
549 int flag_strength_reduce = 0;
551 /* Nonzero enables loop unrolling in unroll.c. Only loops for which the
552 number of iterations can be calculated at compile-time (UNROLL_COMPLETELY,
553 UNROLL_MODULO) or at run-time (preconditioned to be UNROLL_MODULO) are
554 unrolled. */
556 int flag_old_unroll_loops;
558 /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled.
559 This is generally not a win. */
561 int flag_old_unroll_all_loops;
563 /* Enables unrolling of simple loops in loop-unroll.c. */
564 int flag_unroll_loops;
566 /* Enables unrolling of all loops in loop-unroll.c. */
567 int flag_unroll_all_loops;
569 /* Nonzero enables loop peeling. */
570 int flag_peel_loops;
572 /* Nonzero enables loop unswitching. */
573 int flag_unswitch_loops;
575 /* Nonzero enables prefetch optimizations for arrays in loops. */
577 int flag_prefetch_loop_arrays;
579 /* Nonzero forces all invariant computations in loops to be moved
580 outside the loop. */
582 int flag_move_all_movables = 0;
584 /* Nonzero forces all general induction variables in loops to be
585 strength reduced. */
587 int flag_reduce_all_givs = 0;
589 /* Nonzero to perform full register move optimization passes. This is the
590 default for -O2. */
592 int flag_regmove = 0;
594 /* Nonzero for -fwritable-strings:
595 store string constants in data segment and don't uniquize them. */
597 int flag_writable_strings = 0;
599 /* Nonzero means don't put addresses of constant functions in registers.
600 Used for compiling the Unix kernel, where strange substitutions are
601 done on the assembly output. */
603 int flag_no_function_cse = 0;
605 /* Nonzero for -fomit-frame-pointer:
606 don't make a frame pointer in simple functions that don't require one. */
608 int flag_omit_frame_pointer = 0;
610 /* Nonzero means place each function into its own section on those platforms
611 which support arbitrary section names and unlimited numbers of sections. */
613 int flag_function_sections = 0;
615 /* ... and similar for data. */
617 int flag_data_sections = 0;
619 /* Nonzero to inhibit use of define_optimization peephole opts. */
621 int flag_no_peephole = 0;
623 /* Nonzero allows GCC to optimize sibling and tail recursive calls. */
625 int flag_optimize_sibling_calls = 0;
627 /* Nonzero means the front end generally wants `errno' maintained by math
628 operations, like built-in SQRT. */
630 int flag_errno_math = 1;
632 /* Nonzero means that unsafe floating-point math optimizations are allowed
633 for the sake of speed. IEEE compliance is not guaranteed, and operations
634 are allowed to assume that their arguments and results are "normal"
635 (e.g., nonnegative for SQRT). */
637 int flag_unsafe_math_optimizations = 0;
639 /* Nonzero means that no NaNs or +-Infs are expected. */
641 int flag_finite_math_only = 0;
643 /* Zero means that floating-point math operations cannot generate a
644 (user-visible) trap. This is the case, for example, in nonstop
645 IEEE 754 arithmetic. Trapping conditions include division by zero,
646 overflow, underflow, invalid and inexact, but does not include
647 operations on signaling NaNs (see below). */
649 int flag_trapping_math = 1;
651 /* Nonzero means disable transformations observable by signaling NaNs.
652 This option implies that any operation on an IEEE signaling NaN can
653 generate a (user-visible) trap. */
655 int flag_signaling_nans = 0;
657 /* 0 means straightforward implementation of complex divide acceptable.
658 1 means wide ranges of inputs must work for complex divide.
659 2 means C99-like requirements for complex divide (not yet implemented). */
661 int flag_complex_divide_method = 0;
663 /* Nonzero means just do syntax checking; don't output anything. */
665 int flag_syntax_only = 0;
667 /* Nonzero means perform loop optimizer. */
669 int flag_loop_optimize;
671 /* Nonzero means perform crossjumping. */
673 int flag_crossjumping;
675 /* Nonzero means perform if conversion. */
677 int flag_if_conversion;
679 /* Nonzero means perform if conversion after reload. */
681 int flag_if_conversion2;
683 /* Nonzero means to use global dataflow analysis to eliminate
684 useless null pointer tests. */
686 int flag_delete_null_pointer_checks;
688 /* Nonzero means perform global CSE. */
690 int flag_gcse = 0;
692 /* Nonzero means to do the enhanced load motion during gcse, which trys
693 to hoist loads by not killing them when a store to the same location
694 is seen. */
696 int flag_gcse_lm = 1;
698 /* Nonzero means to perform store motion after gcse, which will try to
699 move stores closer to the exit block. Its not very effective without
700 flag_gcse_lm. */
702 int flag_gcse_sm = 1;
704 /* Perform target register optimization before prologue / epilogue
705 threading. */
707 int flag_branch_target_load_optimize = 0;
709 /* Perform target register optimization after prologue / epilogue
710 threading and jump2. */
712 int flag_branch_target_load_optimize2 = 0;
714 /* Nonzero means to rerun cse after loop optimization. This increases
715 compilation time about 20% and picks up a few more common expressions. */
717 int flag_rerun_cse_after_loop;
719 /* Nonzero means to run loop optimizations twice. */
721 int flag_rerun_loop_opt;
723 /* Nonzero for -finline-functions: ok to inline functions that look like
724 good inline candidates. */
726 int flag_inline_functions;
728 /* Nonzero for -fkeep-inline-functions: even if we make a function
729 go inline everywhere, keep its definition around for debugging
730 purposes. */
732 int flag_keep_inline_functions;
734 /* Nonzero means that functions will not be inlined. */
736 int flag_no_inline = 2;
738 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
739 not just because the tree inliner turned us off. */
741 int flag_really_no_inline = 2;
743 /* Nonzero means that we should emit static const variables
744 regardless of whether or not optimization is turned on. */
746 int flag_keep_static_consts = 1;
748 /* Nonzero means we should be saving declaration info into a .X file. */
750 int flag_gen_aux_info = 0;
752 /* Specified name of aux-info file. */
754 const char *aux_info_file_name;
756 /* Nonzero means make the text shared if supported. */
758 int flag_shared_data;
760 /* Nonzero means schedule into delayed branch slots if supported. */
762 int flag_delayed_branch;
764 /* Nonzero if we are compiling pure (sharable) code.
765 Value is 1 if we are doing "small" pic; value is 2 if we're doing
766 "large" pic. */
768 int flag_pic;
770 /* Nonzero if we are compiling position independent code for executable.
771 The value is 1 if we are doing "small" pic; value is 2 if we're doing
772 "large" pic. */
774 int flag_pie;
776 /* Nonzero if we are compiling code for a shared library, zero for
777 executable. */
779 int flag_shlib;
781 /* Set to the default thread-local storage (tls) model to use. */
783 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
785 /* Nonzero means generate extra code for exception handling and enable
786 exception handling. */
788 int flag_exceptions;
790 /* Nonzero means generate frame unwind info table when supported. */
792 int flag_unwind_tables = 0;
794 /* Nonzero means generate frame unwind info table exact at each insn
795 boundary. */
797 int flag_asynchronous_unwind_tables = 0;
799 /* Nonzero means don't place uninitialized global data in common storage
800 by default. */
802 int flag_no_common;
804 /* Nonzero means change certain warnings into errors.
805 Usually these are warnings about failure to conform to some standard. */
807 int flag_pedantic_errors = 0;
809 /* flag_schedule_insns means schedule insns within basic blocks (before
810 local_alloc).
811 flag_schedule_insns_after_reload means schedule insns after
812 global_alloc. */
814 int flag_schedule_insns = 0;
815 int flag_schedule_insns_after_reload = 0;
817 /* When flag_schedule_insns_after_reload is set, use EBB scheduler. */
818 int flag_sched2_use_superblocks = 0;
820 /* When flag_schedule_insns_after_reload is set, construct traces and EBB
821 scheduler. */
822 int flag_sched2_use_traces = 0;
824 /* The following flags have effect only for scheduling before register
825 allocation:
827 flag_schedule_interblock means schedule insns across basic blocks.
828 flag_schedule_speculative means allow speculative motion of non-load insns.
829 flag_schedule_speculative_load means allow speculative motion of some
830 load insns.
831 flag_schedule_speculative_load_dangerous allows speculative motion of more
832 load insns. */
834 int flag_schedule_interblock = 1;
835 int flag_schedule_speculative = 1;
836 int flag_schedule_speculative_load = 0;
837 int flag_schedule_speculative_load_dangerous = 0;
839 int flag_single_precision_constant;
841 /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple
842 by a cheaper branch on a count register. */
843 int flag_branch_on_count_reg = 1;
845 /* -finhibit-size-directive inhibits output of .size for ELF.
846 This is used only for compiling crtstuff.c,
847 and it may be extended to other effects
848 needed for crtstuff.c on other systems. */
849 int flag_inhibit_size_directive = 0;
851 /* -fverbose-asm causes extra commentary information to be produced in
852 the generated assembly code (to make it more readable). This option
853 is generally only of use to those who actually need to read the
854 generated assembly code (perhaps while debugging the compiler itself).
855 -fno-verbose-asm, the default, causes the extra information
856 to be omitted and is useful when comparing two assembler files. */
858 int flag_verbose_asm = 0;
860 /* -dA causes debug commentary information to be produced in
861 the generated assembly code (to make it more readable). This option
862 is generally only of use to those who actually need to read the
863 generated assembly code (perhaps while debugging the compiler itself).
864 Currently, this switch is only used by dwarfout.c; however, it is intended
865 to be a catchall for printing debug information in the assembler file. */
867 int flag_debug_asm = 0;
869 /* -dP causes the rtl to be emitted as a comment in assembly. */
871 int flag_dump_rtl_in_asm = 0;
873 /* -fgnu-linker specifies use of the GNU linker for initializations.
874 (Or, more generally, a linker that handles initializations.)
875 -fno-gnu-linker says that collect2 will be used. */
876 #ifdef USE_COLLECT2
877 int flag_gnu_linker = 0;
878 #else
879 int flag_gnu_linker = 1;
880 #endif
882 /* Nonzero means put zero initialized data in the bss section. */
883 int flag_zero_initialized_in_bss = 1;
885 /* Enable SSA. */
886 int flag_ssa = 0;
888 /* Enable ssa conditional constant propagation. */
889 int flag_ssa_ccp = 0;
891 /* Enable ssa aggressive dead code elimination. */
892 int flag_ssa_dce = 0;
894 /* Tag all structures with __attribute__(packed). */
895 int flag_pack_struct = 0;
897 /* Emit code to check for stack overflow; also may cause large objects
898 to be allocated dynamically. */
899 int flag_stack_check;
901 /* When non-NULL, indicates that whenever space is allocated on the
902 stack, the resulting stack pointer must not pass this
903 address---that is, for stacks that grow downward, the stack pointer
904 must always be greater than or equal to this address; for stacks
905 that grow upward, the stack pointer must be less than this address.
906 At present, the rtx may be either a REG or a SYMBOL_REF, although
907 the support provided depends on the backend. */
908 rtx stack_limit_rtx;
910 /* 0 if pointer arguments may alias each other. True in C.
911 1 if pointer arguments may not alias each other but may alias
912 global variables.
913 2 if pointer arguments may not alias each other and may not
914 alias global variables. True in Fortran.
915 This defaults to 0 for C. */
916 int flag_argument_noalias = 0;
918 /* Nonzero if we should do (language-dependent) alias analysis.
919 Typically, this analysis will assume that expressions of certain
920 types do not alias expressions of certain other types. Only used
921 if alias analysis (in general) is enabled. */
922 int flag_strict_aliasing = 0;
924 /* Instrument functions with calls at entry and exit, for profiling. */
925 int flag_instrument_function_entry_exit = 0;
927 /* Nonzero means ignore `#ident' directives. 0 means handle them.
928 On SVR4 targets, it also controls whether or not to emit a
929 string identifying the compiler. */
931 int flag_no_ident = 0;
933 /* This will perform a peephole pass before sched2. */
934 int flag_peephole2 = 0;
936 /* This will try to guess branch probabilities. */
937 int flag_guess_branch_prob = 0;
939 /* -fcheck-bounds causes gcc to generate array bounds checks.
940 For C, C++, ObjC: defaults to off.
941 For Java: defaults to on.
942 For Fortran: defaults to off. */
943 int flag_bounds_check = 0;
945 /* This will attempt to merge constant section constants, if 1 only
946 string constants and constants from constant pool, if 2 also constant
947 variables. */
948 int flag_merge_constants = 1;
950 /* If one, renumber instruction UIDs to reduce the number of
951 unused UIDs if there are a lot of instructions. If greater than
952 one, unconditionally renumber instruction UIDs. */
953 int flag_renumber_insns = 1;
955 /* If nonzero, use the graph coloring register allocator. */
956 int flag_new_regalloc = 0;
958 /* Nonzero if we perform superblock formation. */
960 int flag_tracer = 0;
962 /* Nonzero if we perform whole unit at a time compilation. */
964 int flag_unit_at_a_time = 0;
966 /* Values of the -falign-* flags: how much to align labels in code.
967 0 means `use default', 1 means `don't align'.
968 For each variable, there is an _log variant which is the power
969 of two not less than the variable, for .align output. */
971 int align_loops;
972 int align_loops_log;
973 int align_loops_max_skip;
974 int align_jumps;
975 int align_jumps_log;
976 int align_jumps_max_skip;
977 int align_labels;
978 int align_labels_log;
979 int align_labels_max_skip;
980 int align_functions;
981 int align_functions_log;
983 /* Like align_functions_log above, but used by front-ends to force the
984 minimum function alignment. Zero means no alignment is forced. */
985 int force_align_functions_log;
987 /* Table of supported debugging formats. */
988 static const struct
990 const char *const arg;
991 /* Since PREFERRED_DEBUGGING_TYPE isn't necessarily a
992 constant expression, we use NO_DEBUG in its place. */
993 const enum debug_info_type debug_type;
994 const int use_extensions_p;
995 const char *const description;
996 } *da,
997 debug_args[] =
999 { "", NO_DEBUG, DEFAULT_GDB_EXTENSIONS,
1000 N_("Generate debugging info in default format") },
1001 { "gdb", NO_DEBUG, 1, N_("Generate debugging info in default extended format") },
1002 #ifdef DBX_DEBUGGING_INFO
1003 { "stabs", DBX_DEBUG, 0, N_("Generate STABS format debug info") },
1004 { "stabs+", DBX_DEBUG, 1, N_("Generate extended STABS format debug info") },
1005 #endif
1006 #ifdef DWARF_DEBUGGING_INFO
1007 { "dwarf", DWARF_DEBUG, 0, N_("Generate DWARF-1 format debug info") },
1008 { "dwarf+", DWARF_DEBUG, 1,
1009 N_("Generate extended DWARF-1 format debug info") },
1010 #endif
1011 #ifdef DWARF2_DEBUGGING_INFO
1012 { "dwarf-2", DWARF2_DEBUG, 0, N_("Generate DWARF-2 debug info") },
1013 #endif
1014 #ifdef XCOFF_DEBUGGING_INFO
1015 { "xcoff", XCOFF_DEBUG, 0, N_("Generate XCOFF format debug info") },
1016 { "xcoff+", XCOFF_DEBUG, 1, N_("Generate extended XCOFF format debug info") },
1017 #endif
1018 #ifdef SDB_DEBUGGING_INFO
1019 { "coff", SDB_DEBUG, 0, N_("Generate COFF format debug info") },
1020 #endif
1021 #ifdef VMS_DEBUGGING_INFO
1022 { "vms", VMS_DEBUG, 0, N_("Generate VMS format debug info") },
1023 #endif
1024 { 0, 0, 0, 0 }
1027 typedef struct
1029 const char *const string;
1030 int *const variable;
1031 const int on_value;
1033 lang_independent_options;
1035 /* Nonzero if signed arithmetic overflow should trap. */
1036 int flag_trapv = 0;
1038 /* Nonzero if signed arithmetic overflow should wrap around. */
1039 int flag_wrapv = 0;
1041 /* Add or remove a leading underscore from user symbols. */
1042 int flag_leading_underscore = -1;
1044 /* The user symbol prefix after having resolved same. */
1045 const char *user_label_prefix;
1047 static const param_info lang_independent_params[] = {
1048 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \
1049 { OPTION, DEFAULT, HELP },
1050 #include "params.def"
1051 #undef DEFPARAM
1052 { NULL, 0, NULL }
1055 /* Table of language-independent -f options.
1056 STRING is the option name. VARIABLE is the address of the variable.
1057 ON_VALUE is the value to store in VARIABLE
1058 if `-fSTRING' is seen as an option.
1059 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
1061 static const lang_independent_options f_options[] =
1063 {"eliminate-dwarf2-dups", &flag_eliminate_dwarf2_dups, 1 },
1064 {"eliminate-unused-debug-symbols", &flag_debug_only_used_symbols, 1 },
1065 {"eliminate-unused-debug-types", &flag_eliminate_unused_debug_types, 1 },
1066 {"float-store", &flag_float_store, 1 },
1067 {"defer-pop", &flag_defer_pop, 1 },
1068 {"omit-frame-pointer", &flag_omit_frame_pointer, 1 },
1069 {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1 },
1070 {"tracer", &flag_tracer, 1 },
1071 {"unit-at-a-time", &flag_unit_at_a_time, 1 },
1072 {"cse-follow-jumps", &flag_cse_follow_jumps, 1 },
1073 {"cse-skip-blocks", &flag_cse_skip_blocks, 1 },
1074 {"expensive-optimizations", &flag_expensive_optimizations, 1 },
1075 {"thread-jumps", &flag_thread_jumps, 1 },
1076 {"strength-reduce", &flag_strength_reduce, 1 },
1077 {"unroll-loops", &flag_unroll_loops, 1 },
1078 {"unroll-all-loops", &flag_unroll_all_loops, 1 },
1079 {"old-unroll-loops", &flag_old_unroll_loops, 1 },
1080 {"old-unroll-all-loops", &flag_old_unroll_all_loops, 1 },
1081 {"peel-loops", &flag_peel_loops, 1 },
1082 {"unswitch-loops", &flag_unswitch_loops, 1 },
1083 {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 },
1084 {"move-all-movables", &flag_move_all_movables, 1 },
1085 {"reduce-all-givs", &flag_reduce_all_givs, 1 },
1086 {"writable-strings", &flag_writable_strings, 1 },
1087 {"peephole", &flag_no_peephole, 0 },
1088 {"force-mem", &flag_force_mem, 1 },
1089 {"force-addr", &flag_force_addr, 1 },
1090 {"function-cse", &flag_no_function_cse, 0 },
1091 {"inline-functions", &flag_inline_functions, 1 },
1092 {"keep-inline-functions", &flag_keep_inline_functions, 1 },
1093 {"inline", &flag_no_inline, 0 },
1094 {"keep-static-consts", &flag_keep_static_consts, 1 },
1095 {"syntax-only", &flag_syntax_only, 1 },
1096 {"shared-data", &flag_shared_data, 1 },
1097 {"caller-saves", &flag_caller_saves, 1 },
1098 {"pcc-struct-return", &flag_pcc_struct_return, 1 },
1099 {"reg-struct-return", &flag_pcc_struct_return, 0 },
1100 {"delayed-branch", &flag_delayed_branch, 1 },
1101 {"gcse", &flag_gcse, 1 },
1102 {"gcse-lm", &flag_gcse_lm, 1 },
1103 {"gcse-sm", &flag_gcse_sm, 1 },
1104 {"branch-target-load-optimize", &flag_branch_target_load_optimize, 1 },
1105 {"branch-target-load-optimize2", &flag_branch_target_load_optimize2, 1 },
1106 {"loop-optimize", &flag_loop_optimize, 1 },
1107 {"crossjumping", &flag_crossjumping, 1 },
1108 {"if-conversion", &flag_if_conversion, 1 },
1109 {"if-conversion2", &flag_if_conversion2, 1 },
1110 {"rerun-cse-after-loop", &flag_rerun_cse_after_loop, 1 },
1111 {"rerun-loop-opt", &flag_rerun_loop_opt, 1 },
1112 {"delete-null-pointer-checks", &flag_delete_null_pointer_checks, 1 },
1113 {"schedule-insns", &flag_schedule_insns, 1 },
1114 {"schedule-insns2", &flag_schedule_insns_after_reload, 1 },
1115 {"sched-interblock",&flag_schedule_interblock, 1 },
1116 {"sched-spec",&flag_schedule_speculative, 1 },
1117 {"sched-spec-load",&flag_schedule_speculative_load, 1 },
1118 {"sched-spec-load-dangerous",&flag_schedule_speculative_load_dangerous, 1 },
1119 {"sched2-use-superblocks", &flag_sched2_use_superblocks, 1 },
1120 {"sched2-use-traces", &flag_sched2_use_traces, 1 },
1121 {"branch-count-reg",&flag_branch_on_count_reg, 1 },
1122 {"pic", &flag_pic, 1 },
1123 {"PIC", &flag_pic, 2 },
1124 {"pie", &flag_pie, 1 },
1125 {"PIE", &flag_pie, 2 },
1126 {"exceptions", &flag_exceptions, 1 },
1127 {"unwind-tables", &flag_unwind_tables, 1 },
1128 {"asynchronous-unwind-tables", &flag_asynchronous_unwind_tables, 1 },
1129 {"non-call-exceptions", &flag_non_call_exceptions, 1 },
1130 {"profile-arcs", &profile_arc_flag, 1 },
1131 {"test-coverage", &flag_test_coverage, 1 },
1132 {"branch-probabilities", &flag_branch_probabilities, 1 },
1133 {"profile", &profile_flag, 1 },
1134 {"reorder-blocks", &flag_reorder_blocks, 1 },
1135 {"reorder-functions", &flag_reorder_functions, 1 },
1136 {"rename-registers", &flag_rename_registers, 1 },
1137 {"cprop-registers", &flag_cprop_registers, 1 },
1138 {"common", &flag_no_common, 0 },
1139 {"inhibit-size-directive", &flag_inhibit_size_directive, 1 },
1140 {"function-sections", &flag_function_sections, 1 },
1141 {"data-sections", &flag_data_sections, 1 },
1142 {"verbose-asm", &flag_verbose_asm, 1 },
1143 {"gnu-linker", &flag_gnu_linker, 1 },
1144 {"regmove", &flag_regmove, 1 },
1145 {"optimize-register-move", &flag_regmove, 1 },
1146 {"pack-struct", &flag_pack_struct, 1 },
1147 {"stack-check", &flag_stack_check, 1 },
1148 {"argument-alias", &flag_argument_noalias, 0 },
1149 {"argument-noalias", &flag_argument_noalias, 1 },
1150 {"argument-noalias-global", &flag_argument_noalias, 2 },
1151 {"strict-aliasing", &flag_strict_aliasing, 1 },
1152 {"align-loops", &align_loops, 0 },
1153 {"align-jumps", &align_jumps, 0 },
1154 {"align-labels", &align_labels, 0 },
1155 {"align-functions", &align_functions, 0 },
1156 {"merge-constants", &flag_merge_constants, 1 },
1157 {"merge-all-constants", &flag_merge_constants, 2 },
1158 {"dump-unnumbered", &flag_dump_unnumbered, 1 },
1159 {"instrument-functions", &flag_instrument_function_entry_exit, 1 },
1160 {"zero-initialized-in-bss", &flag_zero_initialized_in_bss, 1 },
1161 {"ssa", &flag_ssa, 1 },
1162 {"ssa-ccp", &flag_ssa_ccp, 1 },
1163 {"ssa-dce", &flag_ssa_dce, 1 },
1164 {"leading-underscore", &flag_leading_underscore, 1 },
1165 {"ident", &flag_no_ident, 0 },
1166 { "peephole2", &flag_peephole2, 1 },
1167 {"finite-math-only", &flag_finite_math_only, 1 },
1168 { "guess-branch-probability", &flag_guess_branch_prob, 1 },
1169 {"math-errno", &flag_errno_math, 1 },
1170 {"trapping-math", &flag_trapping_math, 1 },
1171 {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1 },
1172 {"signaling-nans", &flag_signaling_nans, 1 },
1173 {"bounds-check", &flag_bounds_check, 1 },
1174 {"single-precision-constant", &flag_single_precision_constant, 1 },
1175 {"time-report", &time_report, 1 },
1176 {"mem-report", &mem_report, 1 },
1177 { "trapv", &flag_trapv, 1 },
1178 { "wrapv", &flag_wrapv, 1 },
1179 { "new-ra", &flag_new_regalloc, 1 }
1182 /* Here is a table, controlled by the tm.h file, listing each -m switch
1183 and which bits in `target_switches' it should set or clear.
1184 If VALUE is positive, it is bits to set.
1185 If VALUE is negative, -VALUE is bits to clear.
1186 (The sign bit is not used so there is no confusion.) */
1188 static const struct
1190 const char *const name;
1191 const int value;
1192 const char *const description;
1194 target_switches[] = TARGET_SWITCHES;
1196 /* This table is similar, but allows the switch to have a value. */
1198 #ifdef TARGET_OPTIONS
1199 static const struct
1201 const char *const prefix;
1202 const char **const variable;
1203 const char *const description;
1204 const char *const value;
1206 target_options[] = TARGET_OPTIONS;
1207 #endif
1209 /* Nonzero means warn about function definitions that default the return type
1210 or that use a null return and have a return-type other than void. */
1212 int warn_return_type;
1214 /* Output files for assembler code (real compiler output)
1215 and debugging dumps. */
1217 FILE *asm_out_file;
1218 FILE *aux_info_file;
1219 FILE *rtl_dump_file = NULL;
1220 FILE *cgraph_dump_file = NULL;
1222 /* The current working directory of a translation. It's generally the
1223 directory from which compilation was initiated, but a preprocessed
1224 file may specify the original directory in which it was
1225 created. */
1227 static const char *src_pwd;
1229 /* Initialize src_pwd with the given string, and return true. If it
1230 was already initialized, return false. As a special case, it may
1231 be called with a NULL argument to test whether src_pwd has NOT been
1232 initialized yet. */
1234 bool
1235 set_src_pwd (const char *pwd)
1237 if (src_pwd)
1238 return false;
1240 src_pwd = xstrdup (pwd);
1241 return true;
1244 /* Return the directory from which the translation unit was initiated,
1245 in case set_src_pwd() was not called before to assign it a
1246 different value. */
1248 const char *
1249 get_src_pwd (void)
1251 if (! src_pwd)
1252 src_pwd = getpwd ();
1254 return src_pwd;
1257 /* Set up a default flag_random_seed and local_tick, unless the user
1258 already specified one. */
1260 static void
1261 randomize (void)
1263 if (!flag_random_seed)
1265 unsigned HOST_WIDE_INT value;
1266 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
1268 /* Get some more or less random data. */
1269 #ifdef HAVE_GETTIMEOFDAY
1271 struct timeval tv;
1273 gettimeofday (&tv, NULL);
1274 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
1276 #else
1278 time_t now = time (NULL);
1280 if (now != (time_t)-1)
1281 local_tick = (unsigned) now;
1283 #endif
1284 value = local_tick ^ getpid ();
1286 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
1287 flag_random_seed = random_seed;
1289 else if (!local_tick)
1290 local_tick = -1;
1294 /* Decode the string P as an integral parameter.
1295 If the string is indeed an integer return its numeric value else
1296 issue an Invalid Option error for the option PNAME and return DEFVAL.
1297 If PNAME is zero just return DEFVAL, do not call error. */
1300 read_integral_parameter (const char *p, const char *pname, const int defval)
1302 const char *endp = p;
1304 while (*endp)
1306 if (ISDIGIT (*endp))
1307 endp++;
1308 else
1309 break;
1312 if (*endp != 0)
1314 if (pname != 0)
1315 error ("invalid option argument `%s'", pname);
1316 return defval;
1319 return atoi (p);
1322 /* Return the logarithm of X, base 2, considering X unsigned,
1323 if X is a power of 2. Otherwise, returns -1.
1325 This should be used via the `exact_log2' macro. */
1328 exact_log2_wide (unsigned HOST_WIDE_INT x)
1330 int log = 0;
1331 /* Test for 0 or a power of 2. */
1332 if (x == 0 || x != (x & -x))
1333 return -1;
1334 while ((x >>= 1) != 0)
1335 log++;
1336 return log;
1339 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
1340 If X is 0, return -1.
1342 This should be used via the floor_log2 macro. */
1345 floor_log2_wide (unsigned HOST_WIDE_INT x)
1347 int log = -1;
1348 while (x != 0)
1349 log++,
1350 x >>= 1;
1351 return log;
1354 /* Handler for fatal signals, such as SIGSEGV. These are transformed
1355 into ICE messages, which is much more user friendly. In case the
1356 error printer crashes, reset the signal to prevent infinite recursion. */
1358 static void
1359 crash_signal (int signo)
1361 signal (signo, SIG_DFL);
1362 internal_error ("%s", strsignal (signo));
1365 /* Arrange to dump core on error. (The regular error message is still
1366 printed first, except in the case of abort().) */
1368 static void
1369 setup_core_dumping (void)
1371 #ifdef SIGABRT
1372 signal (SIGABRT, SIG_DFL);
1373 #endif
1374 #if defined(HAVE_SETRLIMIT)
1376 struct rlimit rlim;
1377 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
1378 fatal_error ("getting core file size maximum limit: %m");
1379 rlim.rlim_cur = rlim.rlim_max;
1380 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
1381 fatal_error ("setting core file size limit to maximum: %m");
1383 #endif
1384 diagnostic_abort_on_error (global_dc);
1388 /* Strip off a legitimate source ending from the input string NAME of
1389 length LEN. Rather than having to know the names used by all of
1390 our front ends, we strip off an ending of a period followed by
1391 up to five characters. (Java uses ".class".) */
1393 void
1394 strip_off_ending (char *name, int len)
1396 int i;
1397 for (i = 2; i < 6 && len > i; i++)
1399 if (name[len - i] == '.')
1401 name[len - i] = '\0';
1402 break;
1407 /* Output a quoted string. */
1409 void
1410 output_quoted_string (FILE *asm_file, const char *string)
1412 #ifdef OUTPUT_QUOTED_STRING
1413 OUTPUT_QUOTED_STRING (asm_file, string);
1414 #else
1415 char c;
1417 putc ('\"', asm_file);
1418 while ((c = *string++) != 0)
1420 if (ISPRINT (c))
1422 if (c == '\"' || c == '\\')
1423 putc ('\\', asm_file);
1424 putc (c, asm_file);
1426 else
1427 fprintf (asm_file, "\\%03o", (unsigned char) c);
1429 putc ('\"', asm_file);
1430 #endif
1433 /* Output a file name in the form wanted by System V. */
1435 void
1436 output_file_directive (FILE *asm_file, const char *input_name)
1438 int len = strlen (input_name);
1439 const char *na = input_name + len;
1441 /* NA gets INPUT_NAME sans directory names. */
1442 while (na > input_name)
1444 if (IS_DIR_SEPARATOR (na[-1]))
1445 break;
1446 na--;
1449 #ifdef ASM_OUTPUT_MAIN_SOURCE_FILENAME
1450 ASM_OUTPUT_MAIN_SOURCE_FILENAME (asm_file, na);
1451 #else
1452 #ifdef ASM_OUTPUT_SOURCE_FILENAME
1453 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
1454 #else
1455 fprintf (asm_file, "\t.file\t");
1456 output_quoted_string (asm_file, na);
1457 fputc ('\n', asm_file);
1458 #endif
1459 #endif
1462 /* Routine to open a dump file. Return true if the dump file is enabled. */
1464 static int
1465 open_dump_file (enum dump_file_index index, tree decl)
1467 char *dump_name;
1468 const char *open_arg;
1469 char seq[16];
1471 if (! dump_file[index].enabled)
1472 return 0;
1474 timevar_push (TV_DUMP);
1475 if (rtl_dump_file != NULL)
1476 fclose (rtl_dump_file);
1478 sprintf (seq, DUMPFILE_FORMAT, index);
1480 if (! dump_file[index].initialized)
1482 /* If we've not initialized the files, do so now. */
1483 if (graph_dump_format != no_graph
1484 && dump_file[index].graph_dump_p)
1486 dump_name = concat (seq, dump_file[index].extension, NULL);
1487 clean_graph_dump_file (dump_base_name, dump_name);
1488 free (dump_name);
1490 dump_file[index].initialized = 1;
1491 open_arg = "w";
1493 else
1494 open_arg = "a";
1496 dump_name = concat (dump_base_name, seq,
1497 dump_file[index].extension, NULL);
1499 rtl_dump_file = fopen (dump_name, open_arg);
1500 if (rtl_dump_file == NULL)
1501 fatal_error ("can't open %s: %m", dump_name);
1503 free (dump_name);
1505 if (decl)
1506 fprintf (rtl_dump_file, "\n;; Function %s%s\n\n",
1507 (*lang_hooks.decl_printable_name) (decl, 2),
1508 cfun->function_frequency == FUNCTION_FREQUENCY_HOT
1509 ? " (hot)"
1510 : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
1511 ? " (unlikely executed)"
1512 : "");
1514 timevar_pop (TV_DUMP);
1515 return 1;
1518 /* Routine to close a dump file. */
1520 static void
1521 close_dump_file (enum dump_file_index index,
1522 void (*func) (FILE *, rtx),
1523 rtx insns)
1525 if (! rtl_dump_file)
1526 return;
1528 timevar_push (TV_DUMP);
1529 if (insns
1530 && graph_dump_format != no_graph
1531 && dump_file[index].graph_dump_p)
1533 char seq[16];
1534 char *suffix;
1536 sprintf (seq, DUMPFILE_FORMAT, index);
1537 suffix = concat (seq, dump_file[index].extension, NULL);
1538 print_rtl_graph_with_bb (dump_base_name, suffix, insns);
1539 free (suffix);
1542 if (func && insns)
1543 func (rtl_dump_file, insns);
1545 fflush (rtl_dump_file);
1546 fclose (rtl_dump_file);
1548 rtl_dump_file = NULL;
1549 timevar_pop (TV_DUMP);
1552 /* Do any final processing required for the declarations in VEC, of
1553 which there are LEN. We write out inline functions and variables
1554 that have been deferred until this point, but which are required.
1555 Returns nonzero if anything was put out. */
1558 wrapup_global_declarations (tree *vec, int len)
1560 tree decl;
1561 int i;
1562 int reconsider;
1563 int output_something = 0;
1565 for (i = 0; i < len; i++)
1567 decl = vec[i];
1569 /* We're not deferring this any longer. Assignment is
1570 conditional to avoid needlessly dirtying PCH pages. */
1571 if (DECL_DEFER_OUTPUT (decl) != 0)
1572 DECL_DEFER_OUTPUT (decl) = 0;
1574 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
1575 (*lang_hooks.finish_incomplete_decl) (decl);
1578 /* Now emit any global variables or functions that we have been
1579 putting off. We need to loop in case one of the things emitted
1580 here references another one which comes earlier in the list. */
1583 reconsider = 0;
1584 for (i = 0; i < len; i++)
1586 decl = vec[i];
1588 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
1589 continue;
1591 /* Don't write out static consts, unless we still need them.
1593 We also keep static consts if not optimizing (for debugging),
1594 unless the user specified -fno-keep-static-consts.
1595 ??? They might be better written into the debug information.
1596 This is possible when using DWARF.
1598 A language processor that wants static constants to be always
1599 written out (even if it is not used) is responsible for
1600 calling rest_of_decl_compilation itself. E.g. the C front-end
1601 calls rest_of_decl_compilation from finish_decl.
1602 One motivation for this is that is conventional in some
1603 environments to write things like:
1604 static const char rcsid[] = "... version string ...";
1605 intending to force the string to be in the executable.
1607 A language processor that would prefer to have unneeded
1608 static constants "optimized away" would just defer writing
1609 them out until here. E.g. C++ does this, because static
1610 constants are often defined in header files.
1612 ??? A tempting alternative (for both C and C++) would be
1613 to force a constant to be written if and only if it is
1614 defined in a main file, as opposed to an include file. */
1616 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
1618 bool needed = 1;
1620 if (flag_unit_at_a_time
1621 && cgraph_varpool_node (decl)->finalized)
1622 needed = 0;
1623 else if (flag_unit_at_a_time
1624 && (TREE_USED (decl)
1625 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
1626 /* needed */;
1627 else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1628 /* needed */;
1629 else if (DECL_COMDAT (decl))
1630 needed = 0;
1631 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
1632 && (optimize || !flag_keep_static_consts
1633 || DECL_ARTIFICIAL (decl)))
1634 needed = 0;
1636 if (needed)
1638 reconsider = 1;
1639 rest_of_decl_compilation (decl, NULL, 1, 1);
1643 if (TREE_CODE (decl) == FUNCTION_DECL
1644 && DECL_INITIAL (decl) != 0
1645 && DECL_SAVED_INSNS (decl) != 0
1646 && (flag_keep_inline_functions
1647 || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl))
1648 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
1650 reconsider = 1;
1651 output_inline_function (decl);
1655 if (reconsider)
1656 output_something = 1;
1658 while (reconsider);
1660 return output_something;
1663 /* Issue appropriate warnings for the global declarations in VEC (of
1664 which there are LEN). Output debugging information for them. */
1666 void
1667 check_global_declarations (tree *vec, int len)
1669 tree decl;
1670 int i;
1672 for (i = 0; i < len; i++)
1674 decl = vec[i];
1676 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)
1677 && ! TREE_ASM_WRITTEN (decl))
1678 /* Cancel the RTL for this decl so that, if debugging info
1679 output for global variables is still to come,
1680 this one will be omitted. */
1681 SET_DECL_RTL (decl, NULL_RTX);
1683 /* Warn about any function
1684 declared static but not defined.
1685 We don't warn about variables,
1686 because many programs have static variables
1687 that exist only to get some text into the object file. */
1688 if (TREE_CODE (decl) == FUNCTION_DECL
1689 && (warn_unused_function
1690 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1691 && DECL_INITIAL (decl) == 0
1692 && DECL_EXTERNAL (decl)
1693 && ! DECL_ARTIFICIAL (decl)
1694 && ! TREE_PUBLIC (decl))
1696 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
1697 pedwarn ("%H'%F' used but never defined",
1698 &DECL_SOURCE_LOCATION (decl), decl);
1699 else
1700 warning ("%H'%F' declared `static' but never defined",
1701 &DECL_SOURCE_LOCATION (decl), decl);
1702 /* This symbol is effectively an "extern" declaration now. */
1703 TREE_PUBLIC (decl) = 1;
1704 assemble_external (decl);
1707 /* Warn about static fns or vars defined but not used. */
1708 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
1709 || (warn_unused_variable && TREE_CODE (decl) == VAR_DECL))
1710 && ! TREE_USED (decl)
1711 /* The TREE_USED bit for file-scope decls is kept in the identifier,
1712 to handle multiple external decls in different scopes. */
1713 && ! TREE_USED (DECL_NAME (decl))
1714 && ! DECL_EXTERNAL (decl)
1715 && ! TREE_PUBLIC (decl)
1716 /* A volatile variable might be used in some non-obvious way. */
1717 && ! TREE_THIS_VOLATILE (decl)
1718 /* Global register variables must be declared to reserve them. */
1719 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
1720 /* Otherwise, ask the language. */
1721 && (*lang_hooks.decls.warn_unused_global) (decl))
1722 warning ("%H'%D' defined but not used",
1723 &DECL_SOURCE_LOCATION (decl), decl);
1725 /* Avoid confusing the debug information machinery when there are
1726 errors. */
1727 if (errorcount == 0 && sorrycount == 0)
1729 timevar_push (TV_SYMOUT);
1730 (*debug_hooks->global_decl) (decl);
1731 timevar_pop (TV_SYMOUT);
1736 /* Save the current INPUT_LOCATION on the top entry in the
1737 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
1738 INPUT_LOCATION accordingly. */
1740 void
1741 push_srcloc (const char *file, int line)
1743 struct file_stack *fs;
1745 fs = xmalloc (sizeof (struct file_stack));
1746 fs->location = input_location;
1747 fs->next = input_file_stack;
1748 input_filename = file;
1749 input_line = line;
1750 input_file_stack = fs;
1751 input_file_stack_tick++;
1754 /* Pop the top entry off the stack of presently open source files.
1755 Restore the INPUT_LOCATION from the new topmost entry on the
1756 stack. */
1758 void
1759 pop_srcloc (void)
1761 struct file_stack *fs;
1763 fs = input_file_stack;
1764 input_location = fs->location;
1765 input_file_stack = fs->next;
1766 free (fs);
1767 input_file_stack_tick++;
1770 /* Compile an entire translation unit. Write a file of assembly
1771 output and various debugging dumps. */
1773 static void
1774 compile_file (void)
1776 /* Initialize yet another pass. */
1778 init_final (main_input_filename);
1779 coverage_init (aux_base_name);
1781 timevar_push (TV_PARSE);
1783 /* Call the parser, which parses the entire file (calling
1784 rest_of_compilation for each function). */
1785 (*lang_hooks.parse_file) (set_yydebug);
1787 /* In case there were missing block closers,
1788 get us back to the global binding level. */
1789 (*lang_hooks.clear_binding_stack) ();
1791 /* Compilation is now finished except for writing
1792 what's left of the symbol table output. */
1793 timevar_pop (TV_PARSE);
1795 if (flag_syntax_only)
1796 return;
1798 (*lang_hooks.decls.final_write_globals)();
1800 cgraph_varpool_assemble_pending_decls ();
1802 /* This must occur after the loop to output deferred functions.
1803 Else the coverage initializer would not be emitted if all the
1804 functions in this compilation unit were deferred. */
1805 coverage_finish ();
1807 /* Write out any pending weak symbol declarations. */
1809 weak_finish ();
1811 /* Do dbx symbols. */
1812 timevar_push (TV_SYMOUT);
1814 #ifdef DWARF2_UNWIND_INFO
1815 if (dwarf2out_do_frame ())
1816 dwarf2out_frame_finish ();
1817 #endif
1819 (*debug_hooks->finish) (main_input_filename);
1820 timevar_pop (TV_SYMOUT);
1822 /* Output some stuff at end of file if nec. */
1824 dw2_output_indirect_constants ();
1826 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
1828 timevar_push (TV_DUMP);
1829 open_dump_file (DFI_bp, NULL);
1831 end_branch_prob ();
1833 close_dump_file (DFI_bp, NULL, NULL_RTX);
1834 timevar_pop (TV_DUMP);
1837 targetm.asm_out.file_end ();
1839 /* Attach a special .ident directive to the end of the file to identify
1840 the version of GCC which compiled this code. The format of the .ident
1841 string is patterned after the ones produced by native SVR4 compilers. */
1842 #ifdef IDENT_ASM_OP
1843 if (!flag_no_ident)
1844 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1845 IDENT_ASM_OP, version_string);
1846 #endif
1848 if (optimize > 0 && open_dump_file (DFI_combine, NULL))
1850 timevar_push (TV_DUMP);
1851 dump_combine_total_stats (rtl_dump_file);
1852 close_dump_file (DFI_combine, NULL, NULL_RTX);
1853 timevar_pop (TV_DUMP);
1857 /* This is called from various places for FUNCTION_DECL, VAR_DECL,
1858 and TYPE_DECL nodes.
1860 This does nothing for local (non-static) variables, unless the
1861 variable is a register variable with an ASMSPEC. In that case, or
1862 if the variable is not an automatic, it sets up the RTL and
1863 outputs any assembler code (label definition, storage allocation
1864 and initialization).
1866 DECL is the declaration. If ASMSPEC is nonzero, it specifies
1867 the assembler symbol name to be used. TOP_LEVEL is nonzero
1868 if this declaration is not within a function. */
1870 void
1871 rest_of_decl_compilation (tree decl,
1872 const char *asmspec,
1873 int top_level,
1874 int at_end)
1876 /* We deferred calling assemble_alias so that we could collect
1877 other attributes such as visibility. Emit the alias now. */
1879 tree alias;
1880 alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl));
1881 if (alias)
1883 alias = TREE_VALUE (TREE_VALUE (alias));
1884 alias = get_identifier (TREE_STRING_POINTER (alias));
1885 assemble_alias (decl, alias);
1889 /* Forward declarations for nested functions are not "external",
1890 but we need to treat them as if they were. */
1891 if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1892 || TREE_CODE (decl) == FUNCTION_DECL)
1894 timevar_push (TV_VARCONST);
1896 if (asmspec)
1897 make_decl_rtl (decl, asmspec);
1899 /* Don't output anything when a tentative file-scope definition
1900 is seen. But at end of compilation, do output code for them. */
1901 if (at_end || !DECL_DEFER_OUTPUT (decl))
1903 if (flag_unit_at_a_time && !cgraph_global_info_ready
1904 && TREE_CODE (decl) != FUNCTION_DECL && top_level)
1905 cgraph_varpool_finalize_decl (decl);
1906 else
1907 assemble_variable (decl, top_level, at_end, 0);
1910 #ifdef ASM_FINISH_DECLARE_OBJECT
1911 if (decl == last_assemble_variable_decl)
1913 ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl,
1914 top_level, at_end);
1916 #endif
1918 timevar_pop (TV_VARCONST);
1920 else if (DECL_REGISTER (decl) && asmspec != 0)
1922 if (decode_reg_name (asmspec) >= 0)
1924 SET_DECL_RTL (decl, NULL_RTX);
1925 make_decl_rtl (decl, asmspec);
1927 else
1929 error ("invalid register name `%s' for register variable", asmspec);
1930 DECL_REGISTER (decl) = 0;
1931 if (!top_level)
1932 expand_decl (decl);
1935 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1936 else if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1937 && TREE_CODE (decl) == TYPE_DECL)
1939 timevar_push (TV_SYMOUT);
1940 dbxout_symbol (decl, 0);
1941 timevar_pop (TV_SYMOUT);
1943 #endif
1944 #ifdef SDB_DEBUGGING_INFO
1945 else if (write_symbols == SDB_DEBUG && top_level
1946 && TREE_CODE (decl) == TYPE_DECL)
1948 timevar_push (TV_SYMOUT);
1949 sdbout_symbol (decl, 0);
1950 timevar_pop (TV_SYMOUT);
1952 #endif
1953 #ifdef DWARF2_DEBUGGING_INFO
1954 else if ((write_symbols == DWARF2_DEBUG
1955 || write_symbols == VMS_AND_DWARF2_DEBUG)
1956 && top_level
1957 && TREE_CODE (decl) == TYPE_DECL)
1959 timevar_push (TV_SYMOUT);
1960 dwarf2out_decl (decl);
1961 timevar_pop (TV_SYMOUT);
1963 #endif
1966 /* Called after finishing a record, union or enumeral type. */
1968 void
1969 rest_of_type_compilation (
1970 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \
1971 || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO)
1972 tree type,
1973 int toplev
1974 #else
1975 tree type ATTRIBUTE_UNUSED,
1976 int toplev ATTRIBUTE_UNUSED
1977 #endif
1980 /* Avoid confusing the debug information machinery when there are
1981 errors. */
1982 if (errorcount != 0 || sorrycount != 0)
1983 return;
1985 timevar_push (TV_SYMOUT);
1986 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1987 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1988 dbxout_symbol (TYPE_STUB_DECL (type), !toplev);
1989 #endif
1990 #ifdef SDB_DEBUGGING_INFO
1991 if (write_symbols == SDB_DEBUG)
1992 sdbout_symbol (TYPE_STUB_DECL (type), !toplev);
1993 #endif
1994 #ifdef DWARF2_DEBUGGING_INFO
1995 if ((write_symbols == DWARF2_DEBUG
1996 || write_symbols == VMS_AND_DWARF2_DEBUG)
1997 && toplev)
1998 dwarf2out_decl (TYPE_STUB_DECL (type));
1999 #endif
2000 timevar_pop (TV_SYMOUT);
2003 /* Turn the RTL into assembly. */
2004 static void
2005 rest_of_handle_final (tree decl, rtx insns)
2007 timevar_push (TV_FINAL);
2009 rtx x;
2010 const char *fnname;
2012 /* Get the function's name, as described by its RTL. This may be
2013 different from the DECL_NAME name used in the source file. */
2015 x = DECL_RTL (decl);
2016 if (GET_CODE (x) != MEM)
2017 abort ();
2018 x = XEXP (x, 0);
2019 if (GET_CODE (x) != SYMBOL_REF)
2020 abort ();
2021 fnname = XSTR (x, 0);
2023 assemble_start_function (decl, fnname);
2024 final_start_function (insns, asm_out_file, optimize);
2025 final (insns, asm_out_file, optimize, 0);
2026 final_end_function ();
2028 #ifdef IA64_UNWIND_INFO
2029 /* ??? The IA-64 ".handlerdata" directive must be issued before
2030 the ".endp" directive that closes the procedure descriptor. */
2031 output_function_exception_table ();
2032 #endif
2034 assemble_end_function (decl, fnname);
2036 #ifndef IA64_UNWIND_INFO
2037 /* Otherwise, it feels unclean to switch sections in the middle. */
2038 output_function_exception_table ();
2039 #endif
2041 if (! quiet_flag)
2042 fflush (asm_out_file);
2044 /* Release all memory allocated by flow. */
2045 free_basic_block_vars (0);
2047 /* Release all memory held by regsets now. */
2048 regset_release_memory ();
2050 timevar_pop (TV_FINAL);
2052 ggc_collect ();
2055 #ifdef DELAY_SLOTS
2056 /* Run delay slot optimization. */
2057 static void
2058 rest_of_handle_delay_slots (tree decl, rtx insns)
2060 timevar_push (TV_DBR_SCHED);
2061 open_dump_file (DFI_dbr, decl);
2063 dbr_schedule (insns, rtl_dump_file);
2065 close_dump_file (DFI_dbr, print_rtl, insns);
2066 timevar_pop (TV_DBR_SCHED);
2068 ggc_collect ();
2070 #endif
2072 #ifdef STACK_REGS
2073 /* Convert register usage from flat register file usage to a stack
2074 register file. */
2075 static void
2076 rest_of_handle_stack_regs (tree decl, rtx insns)
2078 timevar_push (TV_REG_STACK);
2079 open_dump_file (DFI_stack, decl);
2081 if (reg_to_stack (insns, rtl_dump_file) && optimize)
2083 if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK
2084 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0))
2085 && flag_reorder_blocks)
2087 reorder_basic_blocks ();
2088 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK);
2092 close_dump_file (DFI_stack, print_rtl_with_bb, insns);
2093 timevar_pop (TV_REG_STACK);
2095 ggc_collect ();
2097 #endif
2100 /* Machine independent reorg pass. */
2101 static void
2102 rest_of_handle_machine_reorg (tree decl, rtx insns)
2104 timevar_push (TV_MACH_DEP);
2105 open_dump_file (DFI_mach, decl);
2107 (*targetm.machine_dependent_reorg) ();
2109 close_dump_file (DFI_mach, print_rtl, insns);
2110 timevar_pop (TV_MACH_DEP);
2112 ggc_collect ();
2116 /* Run new register allocator. Return TRUE if we must exit
2117 rest_of_compilation upon return. */
2118 static bool
2119 rest_of_handle_new_regalloc (tree decl, rtx insns, int *rebuild_notes)
2121 int failure;
2123 delete_trivially_dead_insns (insns, max_reg_num ());
2124 reg_alloc ();
2126 timevar_pop (TV_LOCAL_ALLOC);
2127 if (dump_file[DFI_lreg].enabled)
2129 timevar_push (TV_DUMP);
2131 close_dump_file (DFI_lreg, NULL, NULL);
2132 timevar_pop (TV_DUMP);
2135 /* XXX clean up the whole mess to bring live info in shape again. */
2136 timevar_push (TV_GLOBAL_ALLOC);
2137 open_dump_file (DFI_greg, decl);
2139 build_insn_chain (insns);
2140 failure = reload (insns, 0);
2142 timevar_pop (TV_GLOBAL_ALLOC);
2144 if (dump_file[DFI_greg].enabled)
2146 timevar_push (TV_DUMP);
2148 dump_global_regs (rtl_dump_file);
2150 close_dump_file (DFI_greg, print_rtl_with_bb, insns);
2151 timevar_pop (TV_DUMP);
2154 if (failure)
2155 return true;
2157 reload_completed = 1;
2158 *rebuild_notes = 0;
2160 return false;
2163 /* Run old register allocator. Return TRUE if we must exit
2164 rest_of_compilation upon return. */
2165 static bool
2166 rest_of_handle_old_regalloc (tree decl, rtx insns, int *rebuild_notes)
2168 int failure;
2170 /* Allocate the reg_renumber array. */
2171 allocate_reg_info (max_regno, FALSE, TRUE);
2173 /* And the reg_equiv_memory_loc array. */
2174 reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx));
2176 allocate_initial_values (reg_equiv_memory_loc);
2178 regclass (insns, max_reg_num (), rtl_dump_file);
2179 *rebuild_notes = local_alloc ();
2181 timevar_pop (TV_LOCAL_ALLOC);
2183 if (dump_file[DFI_lreg].enabled)
2185 timevar_push (TV_DUMP);
2187 dump_flow_info (rtl_dump_file);
2188 dump_local_alloc (rtl_dump_file);
2190 close_dump_file (DFI_lreg, print_rtl_with_bb, insns);
2191 timevar_pop (TV_DUMP);
2194 ggc_collect ();
2196 timevar_push (TV_GLOBAL_ALLOC);
2197 open_dump_file (DFI_greg, decl);
2199 /* If optimizing, allocate remaining pseudo-regs. Do the reload
2200 pass fixing up any insns that are invalid. */
2202 if (optimize)
2203 failure = global_alloc (rtl_dump_file);
2204 else
2206 build_insn_chain (insns);
2207 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 return failure;
2225 /* Run the regrename and cprop passes. */
2226 static void
2227 rest_of_handle_regrename (tree decl, rtx insns)
2229 timevar_push (TV_RENAME_REGISTERS);
2230 open_dump_file (DFI_rnreg, decl);
2232 if (flag_rename_registers)
2233 regrename_optimize ();
2234 if (flag_cprop_registers)
2235 copyprop_hardreg_forward ();
2237 close_dump_file (DFI_rnreg, print_rtl_with_bb, insns);
2238 timevar_pop (TV_RENAME_REGISTERS);
2241 /* Reorder basic blocks. */
2242 static void
2243 rest_of_handle_reorder_blocks (tree decl, rtx insns)
2245 timevar_push (TV_REORDER_BLOCKS);
2246 open_dump_file (DFI_bbro, decl);
2248 /* Last attempt to optimize CFG, as scheduling, peepholing and insn
2249 splitting possibly introduced more crossjumping opportunities. */
2250 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
2251 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
2253 if (flag_sched2_use_traces && flag_schedule_insns_after_reload)
2254 tracer ();
2255 if (flag_reorder_blocks)
2256 reorder_basic_blocks ();
2257 if (flag_reorder_blocks
2258 || (flag_sched2_use_traces && flag_schedule_insns_after_reload))
2259 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2261 close_dump_file (DFI_bbro, print_rtl_with_bb, insns);
2262 timevar_pop (TV_REORDER_BLOCKS);
2265 #ifdef INSN_SCHEDULING
2266 /* Run instruction scheduler. */
2267 static void
2268 rest_of_handle_sched (tree decl, rtx insns)
2270 timevar_push (TV_SCHED);
2272 /* Print function header into sched dump now
2273 because doing the sched analysis makes some of the dump. */
2274 if (optimize > 0 && flag_schedule_insns)
2276 open_dump_file (DFI_sched, decl);
2278 /* Do control and data sched analysis,
2279 and write some of the results to dump file. */
2281 schedule_insns (rtl_dump_file);
2283 close_dump_file (DFI_sched, print_rtl_with_bb, insns);
2285 timevar_pop (TV_SCHED);
2287 ggc_collect ();
2290 /* Run second scheduling pass after reload. */
2291 static void
2292 rest_of_handle_sched2 (tree decl, rtx insns)
2294 timevar_push (TV_SCHED2);
2295 open_dump_file (DFI_sched2, decl);
2297 /* Do control and data sched analysis again,
2298 and write some more of the results to dump file. */
2300 split_all_insns (1);
2302 if (flag_sched2_use_superblocks || flag_sched2_use_traces)
2304 schedule_ebbs (rtl_dump_file);
2305 /* No liveness updating code yet, but it should be easy to do.
2306 reg-stack recompute the liveness when needed for now. */
2307 count_or_remove_death_notes (NULL, 1);
2308 cleanup_cfg (CLEANUP_EXPENSIVE);
2310 else
2311 schedule_insns (rtl_dump_file);
2313 close_dump_file (DFI_sched2, print_rtl_with_bb, insns);
2314 timevar_pop (TV_SCHED2);
2316 ggc_collect ();
2318 #endif
2320 /* Register allocation pre-pass, to reduce number of moves necessary
2321 for two-address machines. */
2322 static void
2323 rest_of_handle_regmove (tree decl, rtx insns)
2325 timevar_push (TV_REGMOVE);
2326 open_dump_file (DFI_regmove, decl);
2328 regmove_optimize (insns, max_reg_num (), rtl_dump_file);
2330 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2331 close_dump_file (DFI_regmove, print_rtl_with_bb, insns);
2332 timevar_pop (TV_REGMOVE);
2334 ggc_collect ();
2337 /* Run tracer. */
2338 static void
2339 rest_of_handle_tracer (tree decl, rtx insns)
2341 timevar_push (TV_TRACER);
2342 open_dump_file (DFI_tracer, decl);
2343 if (rtl_dump_file)
2344 dump_flow_info (rtl_dump_file);
2345 tracer ();
2346 cleanup_cfg (CLEANUP_EXPENSIVE);
2347 reg_scan (insns, max_reg_num (), 0);
2348 close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ());
2349 timevar_pop (TV_TRACER);
2352 /* If-conversion and CFG cleanup. */
2353 static void
2354 rest_of_handle_if_conversion (tree decl, rtx insns)
2356 open_dump_file (DFI_ce1, decl);
2357 if (flag_if_conversion)
2359 timevar_push (TV_IFCVT);
2360 if (rtl_dump_file)
2361 dump_flow_info (rtl_dump_file);
2362 cleanup_cfg (CLEANUP_EXPENSIVE);
2363 reg_scan (insns, max_reg_num (), 0);
2364 if_convert (0);
2365 timevar_pop (TV_IFCVT);
2367 timevar_push (TV_JUMP);
2368 cleanup_cfg (CLEANUP_EXPENSIVE);
2369 reg_scan (insns, max_reg_num (), 0);
2370 timevar_pop (TV_JUMP);
2371 close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ());
2374 /* Rerun if-conversion, as combine may have simplified things enough
2375 to now meet sequence length restrictions. */
2376 static void
2377 rest_of_handle_if_after_combine (tree decl, rtx insns)
2379 timevar_push (TV_IFCVT);
2380 open_dump_file (DFI_ce2, decl);
2382 no_new_pseudos = 0;
2383 if_convert (1);
2384 no_new_pseudos = 1;
2386 close_dump_file (DFI_ce2, print_rtl_with_bb, insns);
2387 timevar_pop (TV_IFCVT);
2390 /* Do branch profiling and static profile estimation passes. */
2391 static void
2392 rest_of_handle_branch_prob (tree decl, rtx insns)
2394 struct loops loops;
2396 timevar_push (TV_BRANCH_PROB);
2397 open_dump_file (DFI_bp, decl);
2398 if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
2399 branch_prob ();
2401 /* Discover and record the loop depth at the head of each basic
2402 block. The loop infrastructure does the real job for us. */
2403 flow_loops_find (&loops, LOOP_TREE);
2405 if (rtl_dump_file)
2406 flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
2408 /* Estimate using heuristics if no profiling info is available. */
2409 if (flag_guess_branch_prob)
2410 estimate_probability (&loops);
2412 flow_loops_free (&loops);
2413 close_dump_file (DFI_bp, print_rtl_with_bb, insns);
2414 timevar_pop (TV_BRANCH_PROB);
2417 /* Do control and data flow analysis; write some of the results to the
2418 dump file. */
2419 static void
2420 rest_of_handle_cfg (tree decl, rtx insns)
2422 open_dump_file (DFI_cfg, decl);
2423 if (rtl_dump_file)
2424 dump_flow_info (rtl_dump_file);
2425 if (optimize)
2426 cleanup_cfg (CLEANUP_EXPENSIVE
2427 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2429 /* It may make more sense to mark constant functions after dead code is
2430 eliminated by life_analysis, but we need to do it early, as -fprofile-arcs
2431 may insert code making function non-constant, but we still must consider
2432 it as constant, otherwise -fbranch-probabilities will not read data back.
2434 life_analysis rarely eliminates modification of external memory.
2436 if (optimize)
2437 mark_constant_function ();
2439 close_dump_file (DFI_cfg, print_rtl_with_bb, insns);
2442 /* Purge addressofs. */
2443 static void
2444 rest_of_handle_addressof (tree decl, rtx insns)
2446 open_dump_file (DFI_addressof, decl);
2448 purge_addressof (insns);
2449 if (optimize && purge_all_dead_edges (0))
2450 delete_unreachable_blocks ();
2451 reg_scan (insns, max_reg_num (), 1);
2453 close_dump_file (DFI_addressof, print_rtl, insns);
2456 /* We may have potential sibling or tail recursion sites. Select one
2457 (of possibly multiple) methods of performing the call. */
2458 static void
2459 rest_of_handle_sibling_calls (rtx insns)
2461 rtx insn;
2462 optimize_sibling_and_tail_recursive_calls ();
2464 /* Recompute the CFG as sibling optimization clobbers it randomly. */
2465 free_bb_for_insn ();
2466 find_exception_handler_labels ();
2467 rebuild_jump_labels (insns);
2468 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2470 /* There is pass ordering problem - we must lower NOTE_INSN_PREDICTION
2471 notes before simplifying cfg and we must do lowering after sibcall
2472 that unhides parts of RTL chain and cleans up the CFG.
2474 Until sibcall is replaced by tree-level optimizer, lets just
2475 sweep away the NOTE_INSN_PREDICTION notes that leaked out. */
2476 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2477 if (GET_CODE (insn) == NOTE
2478 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
2479 delete_insn (insn);
2481 close_dump_file (DFI_sibling, print_rtl, get_insns ());
2484 /* Perform jump bypassing and control flow optimizations. */
2485 static void
2486 rest_of_handle_jump_bypass (tree decl, rtx insns)
2488 timevar_push (TV_BYPASS);
2489 open_dump_file (DFI_bypass, decl);
2491 cleanup_cfg (CLEANUP_EXPENSIVE);
2493 if (bypass_jumps (rtl_dump_file))
2495 rebuild_jump_labels (insns);
2496 cleanup_cfg (CLEANUP_EXPENSIVE);
2497 delete_trivially_dead_insns (insns, max_reg_num ());
2500 close_dump_file (DFI_bypass, print_rtl_with_bb, insns);
2501 timevar_pop (TV_BYPASS);
2503 ggc_collect ();
2505 #ifdef ENABLE_CHECKING
2506 verify_flow_info ();
2507 #endif
2510 /* Handle inlining of functions in rest_of_compilation. Return TRUE
2511 if we must exit rest_of_compilation upon return. */
2512 static bool
2513 rest_of_handle_inlining (tree decl)
2515 rtx insns;
2516 int inlinable = 0;
2517 tree parent;
2518 const char *lose;
2520 /* If we are reconsidering an inline function at the end of
2521 compilation, skip the stuff for making it inline. */
2522 if (DECL_SAVED_INSNS (decl) != 0)
2523 return 0;
2525 /* If this is nested inside an inlined external function, pretend
2526 it was only declared. Since we cannot inline such functions,
2527 generating code for this one is not only not necessary but will
2528 confuse some debugging output writers. */
2529 for (parent = DECL_CONTEXT (current_function_decl);
2530 parent != NULL_TREE;
2531 parent = get_containing_scope (parent))
2532 if (TREE_CODE (parent) == FUNCTION_DECL
2533 && DECL_INLINE (parent) && DECL_EXTERNAL (parent))
2535 DECL_INITIAL (decl) = 0;
2536 return true;
2538 else if (TYPE_P (parent))
2539 /* A function in a local class should be treated normally. */
2540 break;
2542 /* If requested, consider whether to make this function inline. */
2543 if ((DECL_INLINE (decl) && !flag_no_inline)
2544 || flag_inline_functions)
2546 timevar_push (TV_INTEGRATION);
2547 lose = function_cannot_inline_p (decl);
2548 timevar_pop (TV_INTEGRATION);
2549 if (lose || ! optimize)
2551 if (warn_inline && lose && DECL_INLINE (decl))
2553 char *msg = xmalloc (2 + strlen (lose) + 1);
2554 msg[0] = '%';
2555 msg[1] = 'H';
2556 strcpy(msg + 2, lose);
2557 warning (msg, &DECL_SOURCE_LOCATION (decl));
2558 free (msg);
2560 DECL_ABSTRACT_ORIGIN (decl) = 0;
2561 /* Don't really compile an extern inline function.
2562 If we can't make it inline, pretend
2563 it was only declared. */
2564 if (DECL_EXTERNAL (decl))
2566 DECL_INITIAL (decl) = 0;
2567 return true;
2570 else
2571 inlinable = DECL_INLINE (decl) = 1;
2574 insns = get_insns ();
2576 /* Dump the rtl code if we are dumping rtl. */
2578 if (open_dump_file (DFI_rtl, decl))
2580 if (DECL_SAVED_INSNS (decl))
2581 fprintf (rtl_dump_file, ";; (integrable)\n\n");
2582 close_dump_file (DFI_rtl, print_rtl, insns);
2585 /* Convert from NOTE_INSN_EH_REGION style notes, and do other
2586 sorts of eh initialization. Delay this until after the
2587 initial rtl dump so that we can see the original nesting. */
2588 convert_from_eh_region_ranges ();
2590 /* If function is inline, and we don't yet know whether to
2591 compile it by itself, defer decision till end of compilation.
2592 wrapup_global_declarations will (indirectly) call
2593 rest_of_compilation again for those functions that need to
2594 be output. Also defer those functions that we are supposed
2595 to defer. */
2597 if (inlinable
2598 || (DECL_INLINE (decl)
2599 && flag_inline_functions
2600 && ((! TREE_PUBLIC (decl) && ! TREE_ADDRESSABLE (decl)
2601 && ! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
2602 && ! flag_keep_inline_functions)
2603 || DECL_EXTERNAL (decl))))
2604 DECL_DEFER_OUTPUT (decl) = 1;
2606 if (DECL_INLINE (decl))
2607 /* DWARF wants separate debugging info for abstract and
2608 concrete instances of all inline functions, including those
2609 declared inline but not inlined, and those inlined even
2610 though they weren't declared inline. Conveniently, that's
2611 what DECL_INLINE means at this point. */
2612 (*debug_hooks->deferred_inline_function) (decl);
2614 if (DECL_DEFER_OUTPUT (decl))
2616 /* If -Wreturn-type, we have to do a bit of compilation. We just
2617 want to call cleanup the cfg to figure out whether or not we can
2618 fall off the end of the function; we do the minimum amount of
2619 work necessary to make that safe. */
2620 if (warn_return_type)
2622 int saved_optimize = optimize;
2624 optimize = 0;
2625 rebuild_jump_labels (insns);
2626 find_exception_handler_labels ();
2627 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2628 cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
2629 optimize = saved_optimize;
2631 /* CFG is no longer maintained up-to-date. */
2632 free_bb_for_insn ();
2635 set_nothrow_function_flags ();
2636 if (current_function_nothrow)
2637 /* Now we know that this can't throw; set the flag for the benefit
2638 of other functions later in this translation unit. */
2639 TREE_NOTHROW (current_function_decl) = 1;
2641 timevar_push (TV_INTEGRATION);
2642 save_for_inline (decl);
2643 timevar_pop (TV_INTEGRATION);
2644 DECL_SAVED_INSNS (decl)->inlinable = inlinable;
2645 return true;
2648 /* If specified extern inline but we aren't inlining it, we are
2649 done. This goes for anything that gets here with DECL_EXTERNAL
2650 set, not just things with DECL_INLINE. */
2651 return (bool) DECL_EXTERNAL (decl);
2654 /* Rest of compilation helper to convert the rtl to SSA form. */
2655 static rtx
2656 rest_of_handle_ssa (tree decl, rtx insns)
2658 timevar_push (TV_TO_SSA);
2659 open_dump_file (DFI_ssa, decl);
2661 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2662 convert_to_ssa ();
2664 close_dump_file (DFI_ssa, print_rtl_with_bb, insns);
2665 timevar_pop (TV_TO_SSA);
2667 /* Perform sparse conditional constant propagation, if requested. */
2668 if (flag_ssa_ccp)
2670 timevar_push (TV_SSA_CCP);
2671 open_dump_file (DFI_ssa_ccp, decl);
2673 ssa_const_prop ();
2675 close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ());
2676 timevar_pop (TV_SSA_CCP);
2679 /* It would be useful to cleanup the CFG at this point, but block
2680 merging and possibly other transformations might leave a PHI
2681 node in the middle of a basic block, which is a strict no-no. */
2683 /* The SSA implementation uses basic block numbers in its phi
2684 nodes. Thus, changing the control-flow graph or the basic
2685 blocks, e.g., calling find_basic_blocks () or cleanup_cfg (),
2686 may cause problems. */
2688 if (flag_ssa_dce)
2690 /* Remove dead code. */
2692 timevar_push (TV_SSA_DCE);
2693 open_dump_file (DFI_ssa_dce, decl);
2695 insns = get_insns ();
2696 ssa_eliminate_dead_code ();
2698 close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns);
2699 timevar_pop (TV_SSA_DCE);
2702 /* Convert from SSA form. */
2704 timevar_push (TV_FROM_SSA);
2705 open_dump_file (DFI_ussa, decl);
2707 convert_from_ssa ();
2708 /* New registers have been created. Rescan their usage. */
2709 reg_scan (insns, max_reg_num (), 1);
2711 close_dump_file (DFI_ussa, print_rtl_with_bb, insns);
2712 timevar_pop (TV_FROM_SSA);
2714 ggc_collect ();
2716 return insns;
2719 /* Try to identify useless null pointer tests and delete them. */
2720 static void
2721 rest_of_handle_null_pointer (tree decl, rtx insns)
2723 open_dump_file (DFI_null, decl);
2724 if (rtl_dump_file)
2725 dump_flow_info (rtl_dump_file);
2727 if (delete_null_pointer_checks (insns))
2728 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2730 close_dump_file (DFI_null, print_rtl_with_bb, insns);
2733 /* Try combining insns through substitution. */
2734 static void
2735 rest_of_handle_combine (tree decl, rtx insns)
2737 int rebuild_jump_labels_after_combine = 0;
2739 timevar_push (TV_COMBINE);
2740 open_dump_file (DFI_combine, decl);
2742 rebuild_jump_labels_after_combine
2743 = combine_instructions (insns, max_reg_num ());
2745 /* Combining insns may have turned an indirect jump into a
2746 direct jump. Rebuild the JUMP_LABEL fields of jumping
2747 instructions. */
2748 if (rebuild_jump_labels_after_combine)
2750 timevar_push (TV_JUMP);
2751 rebuild_jump_labels (insns);
2752 timevar_pop (TV_JUMP);
2754 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE);
2757 close_dump_file (DFI_combine, print_rtl_with_bb, insns);
2758 timevar_pop (TV_COMBINE);
2760 ggc_collect ();
2763 /* Perform life analysis. */
2764 static void
2765 rest_of_handle_life (tree decl, rtx insns)
2767 open_dump_file (DFI_life, decl);
2768 regclass_init ();
2770 #ifdef ENABLE_CHECKING
2771 verify_flow_info ();
2772 #endif
2773 life_analysis (insns, rtl_dump_file, PROP_FINAL);
2774 if (optimize)
2775 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE
2776 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
2777 timevar_pop (TV_FLOW);
2779 if (warn_uninitialized)
2781 uninitialized_vars_warning (DECL_INITIAL (decl));
2782 if (extra_warnings)
2783 setjmp_args_warning ();
2786 if (optimize)
2788 if (!flag_new_regalloc && initialize_uninitialized_subregs ())
2790 /* Insns were inserted, and possibly pseudos created, so
2791 things might look a bit different. */
2792 insns = get_insns ();
2793 allocate_reg_life_data ();
2794 update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES,
2795 PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES);
2799 no_new_pseudos = 1;
2801 close_dump_file (DFI_life, print_rtl_with_bb, insns);
2803 ggc_collect ();
2806 /* Perform common subexpression elimination. Nonzero value from
2807 `cse_main' means that jumps were simplified and some code may now
2808 be unreachable, so do jump optimization again. */
2809 static void
2810 rest_of_handle_cse (tree decl, rtx insns)
2812 int tem;
2814 open_dump_file (DFI_cse, decl);
2815 if (rtl_dump_file)
2816 dump_flow_info (rtl_dump_file);
2817 timevar_push (TV_CSE);
2819 reg_scan (insns, max_reg_num (), 1);
2821 tem = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2822 if (tem)
2823 rebuild_jump_labels (insns);
2824 purge_all_dead_edges (0);
2826 delete_trivially_dead_insns (insns, max_reg_num ());
2828 /* If we are not running more CSE passes, then we are no longer
2829 expecting CSE to be run. But always rerun it in a cheap mode. */
2830 cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse;
2832 if (tem || optimize > 1)
2833 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2834 /* Try to identify useless null pointer tests and delete them. */
2835 if (flag_delete_null_pointer_checks)
2837 timevar_push (TV_JUMP);
2839 if (delete_null_pointer_checks (insns))
2840 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2841 timevar_pop (TV_JUMP);
2844 /* The second pass of jump optimization is likely to have
2845 removed a bunch more instructions. */
2846 renumber_insns (rtl_dump_file);
2848 timevar_pop (TV_CSE);
2849 close_dump_file (DFI_cse, print_rtl_with_bb, insns);
2852 /* Run second CSE pass after loop optimizations. */
2853 static void
2854 rest_of_handle_cse2 (tree decl, rtx insns)
2856 int tem;
2858 timevar_push (TV_CSE2);
2859 open_dump_file (DFI_cse2, decl);
2860 if (rtl_dump_file)
2861 dump_flow_info (rtl_dump_file);
2862 /* CFG is no longer maintained up-to-date. */
2863 tem = cse_main (insns, max_reg_num (), 1, rtl_dump_file);
2864 purge_all_dead_edges (0);
2865 delete_trivially_dead_insns (insns, max_reg_num ());
2867 if (tem)
2869 timevar_push (TV_JUMP);
2870 rebuild_jump_labels (insns);
2871 cleanup_cfg (CLEANUP_EXPENSIVE);
2872 timevar_pop (TV_JUMP);
2874 reg_scan (insns, max_reg_num (), 0);
2875 close_dump_file (DFI_cse2, print_rtl_with_bb, insns);
2876 ggc_collect ();
2877 timevar_pop (TV_CSE2);
2880 /* Perform global cse. */
2881 static void
2882 rest_of_handle_gcse (tree decl, rtx insns)
2884 int save_csb, save_cfj;
2885 int tem2 = 0, tem;
2887 timevar_push (TV_GCSE);
2888 open_dump_file (DFI_gcse, decl);
2890 tem = gcse_main (insns, rtl_dump_file);
2891 rebuild_jump_labels (insns);
2892 delete_trivially_dead_insns (insns, max_reg_num ());
2894 save_csb = flag_cse_skip_blocks;
2895 save_cfj = flag_cse_follow_jumps;
2896 flag_cse_skip_blocks = flag_cse_follow_jumps = 0;
2898 /* Instantiate any remaining CONSTANT_P_RTX nodes. */
2899 if (current_function_calls_constant_p)
2900 purge_builtin_constant_p ();
2902 /* If -fexpensive-optimizations, re-run CSE to clean up things done
2903 by gcse. */
2904 if (flag_expensive_optimizations)
2906 timevar_push (TV_CSE);
2907 reg_scan (insns, max_reg_num (), 1);
2908 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2909 purge_all_dead_edges (0);
2910 delete_trivially_dead_insns (insns, max_reg_num ());
2911 timevar_pop (TV_CSE);
2912 cse_not_expected = !flag_rerun_cse_after_loop;
2915 /* If gcse or cse altered any jumps, rerun jump optimizations to clean
2916 things up. Then possibly re-run CSE again. */
2917 while (tem || tem2)
2919 tem = tem2 = 0;
2920 timevar_push (TV_JUMP);
2921 rebuild_jump_labels (insns);
2922 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2923 timevar_pop (TV_JUMP);
2925 if (flag_expensive_optimizations)
2927 timevar_push (TV_CSE);
2928 reg_scan (insns, max_reg_num (), 1);
2929 tem2 = cse_main (insns, max_reg_num (), 0, rtl_dump_file);
2930 purge_all_dead_edges (0);
2931 delete_trivially_dead_insns (insns, max_reg_num ());
2932 timevar_pop (TV_CSE);
2936 close_dump_file (DFI_gcse, print_rtl_with_bb, insns);
2937 timevar_pop (TV_GCSE);
2939 ggc_collect ();
2940 flag_cse_skip_blocks = save_csb;
2941 flag_cse_follow_jumps = save_cfj;
2942 #ifdef ENABLE_CHECKING
2943 verify_flow_info ();
2944 #endif
2947 /* Move constant computations out of loops. */
2948 static void
2949 rest_of_handle_loop_optimize (tree decl, rtx insns)
2951 int do_unroll, do_prefetch;
2953 timevar_push (TV_LOOP);
2954 delete_dead_jumptables ();
2955 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
2956 open_dump_file (DFI_loop, decl);
2958 /* CFG is no longer maintained up-to-date. */
2959 free_bb_for_insn ();
2961 if (flag_unroll_loops)
2962 do_unroll = 0; /* Having two unrollers is useless. */
2963 else
2964 do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
2965 do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
2967 if (flag_rerun_loop_opt)
2969 cleanup_barriers ();
2971 /* We only want to perform unrolling once. */
2972 loop_optimize (insns, rtl_dump_file, do_unroll);
2973 do_unroll = 0;
2975 /* The first call to loop_optimize makes some instructions
2976 trivially dead. We delete those instructions now in the
2977 hope that doing so will make the heuristics in loop work
2978 better and possibly speed up compilation. */
2979 delete_trivially_dead_insns (insns, max_reg_num ());
2981 /* The regscan pass is currently necessary as the alias
2982 analysis code depends on this information. */
2983 reg_scan (insns, max_reg_num (), 1);
2985 cleanup_barriers ();
2986 loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
2988 /* Loop can create trivially dead instructions. */
2989 delete_trivially_dead_insns (insns, max_reg_num ());
2990 close_dump_file (DFI_loop, print_rtl, insns);
2991 timevar_pop (TV_LOOP);
2992 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
2994 ggc_collect ();
2997 /* Perform loop optimizations. It might be better to do them a bit
2998 sooner, but we want the profile feedback to work more
2999 efficiently. */
3000 static void
3001 rest_of_handle_loop2 (tree decl, rtx insns)
3003 struct loops *loops;
3004 timevar_push (TV_LOOP);
3005 open_dump_file (DFI_loop2, decl);
3006 if (rtl_dump_file)
3007 dump_flow_info (rtl_dump_file);
3009 loops = loop_optimizer_init (rtl_dump_file);
3011 if (loops)
3013 /* The optimizations: */
3014 if (flag_unswitch_loops)
3015 unswitch_loops (loops);
3017 if (flag_peel_loops || flag_unroll_loops)
3018 unroll_and_peel_loops (loops,
3019 (flag_peel_loops ? UAP_PEEL : 0) |
3020 (flag_unroll_loops ? UAP_UNROLL : 0) |
3021 (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0));
3023 loop_optimizer_finalize (loops, rtl_dump_file);
3026 cleanup_cfg (CLEANUP_EXPENSIVE);
3027 delete_trivially_dead_insns (insns, max_reg_num ());
3028 reg_scan (insns, max_reg_num (), 0);
3029 if (rtl_dump_file)
3030 dump_flow_info (rtl_dump_file);
3031 close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ());
3032 timevar_pop (TV_LOOP);
3033 ggc_collect ();
3036 /* This is called from finish_function (within langhooks.parse_file)
3037 after each top-level definition is parsed.
3038 It is supposed to compile that function or variable
3039 and output the assembler code for it.
3040 After we return, the tree storage is freed. */
3042 void
3043 rest_of_compilation (tree decl)
3045 rtx insns;
3046 int rebuild_label_notes_after_reload;
3048 timevar_push (TV_REST_OF_COMPILATION);
3050 /* Register rtl specific functions for cfg. */
3051 rtl_register_cfg_hooks ();
3053 /* Now that we're out of the frontend, we shouldn't have any more
3054 CONCATs anywhere. */
3055 generating_concat_p = 0;
3057 /* When processing delayed functions, prepare_function_start() won't
3058 have been run to re-initialize it. */
3059 cse_not_expected = ! optimize;
3061 /* First, make sure that NOTE_BLOCK is set correctly for each
3062 NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */
3063 if (!cfun->x_whole_function_mode_p)
3064 identify_blocks ();
3066 /* In function-at-a-time mode, we do not attempt to keep the BLOCK
3067 tree in sensible shape. So, we just recalculate it here. */
3068 if (cfun->x_whole_function_mode_p)
3069 reorder_blocks ();
3071 init_flow ();
3073 if (rest_of_handle_inlining (decl))
3074 goto exit_rest_of_compilation;
3076 /* If we're emitting a nested function, make sure its parent gets
3077 emitted as well. Doing otherwise confuses debug info. */
3079 tree parent;
3080 for (parent = DECL_CONTEXT (current_function_decl);
3081 parent != NULL_TREE;
3082 parent = get_containing_scope (parent))
3083 if (TREE_CODE (parent) == FUNCTION_DECL)
3084 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1;
3087 /* We are now committed to emitting code for this function. Do any
3088 preparation, such as emitting abstract debug info for the inline
3089 before it gets mangled by optimization. */
3090 if (DECL_INLINE (decl))
3091 (*debug_hooks->outlining_inline_function) (decl);
3093 /* Remove any notes we don't need. That will make iterating
3094 over the instruction sequence faster, and allow the garbage
3095 collector to reclaim the memory used by the notes. */
3096 remove_unnecessary_notes ();
3097 reorder_blocks ();
3099 ggc_collect ();
3101 /* Initialize some variables used by the optimizers. */
3102 init_function_for_compilation ();
3104 if (! DECL_DEFER_OUTPUT (decl))
3105 TREE_ASM_WRITTEN (decl) = 1;
3107 /* Now that integrate will no longer see our rtl, we need not
3108 distinguish between the return value of this function and the
3109 return value of called functions. Also, we can remove all SETs
3110 of subregs of hard registers; they are only here because of
3111 integrate. Also, we can now initialize pseudos intended to
3112 carry magic hard reg data throughout the function. */
3113 rtx_equal_function_value_matters = 0;
3114 purge_hard_subreg_sets (get_insns ());
3116 /* Early return if there were errors. We can run afoul of our
3117 consistency checks, and there's not really much point in fixing them.
3118 Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */
3119 if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type)
3120 || errorcount || sorrycount)
3121 goto exit_rest_of_compilation;
3123 timevar_push (TV_JUMP);
3124 open_dump_file (DFI_sibling, decl);
3125 insns = get_insns ();
3126 rebuild_jump_labels (insns);
3127 find_exception_handler_labels ();
3128 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3130 delete_unreachable_blocks ();
3132 /* We have to issue these warnings now already, because CFG cleanups
3133 further down may destroy the required information. */
3134 check_function_return_warnings ();
3136 /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */
3137 if (flag_guess_branch_prob)
3139 timevar_push (TV_BRANCH_PROB);
3140 note_prediction_to_br_prob ();
3141 timevar_pop (TV_BRANCH_PROB);
3144 if (flag_optimize_sibling_calls)
3145 rest_of_handle_sibling_calls (insns);
3147 timevar_pop (TV_JUMP);
3149 insn_locators_initialize ();
3150 /* Complete generation of exception handling code. */
3151 if (doing_eh (0))
3153 timevar_push (TV_JUMP);
3154 open_dump_file (DFI_eh, decl);
3156 finish_eh_generation ();
3158 close_dump_file (DFI_eh, print_rtl, get_insns ());
3159 timevar_pop (TV_JUMP);
3162 /* Delay emitting hard_reg_initial_value sets until after EH landing pad
3163 generation, which might create new sets. */
3164 emit_initial_value_sets ();
3166 #ifdef FINALIZE_PIC
3167 /* If we are doing position-independent code generation, now
3168 is the time to output special prologues and epilogues.
3169 We do not want to do this earlier, because it just clutters
3170 up inline functions with meaningless insns. */
3171 if (flag_pic)
3172 FINALIZE_PIC;
3173 #endif
3175 insns = get_insns ();
3177 /* Copy any shared structure that should not be shared. */
3178 unshare_all_rtl (current_function_decl, insns);
3180 #ifdef SETJMP_VIA_SAVE_AREA
3181 /* This must be performed before virtual register instantiation.
3182 Please be aware the everything in the compiler that can look
3183 at the RTL up to this point must understand that REG_SAVE_AREA
3184 is just like a use of the REG contained inside. */
3185 if (current_function_calls_alloca)
3186 optimize_save_area_alloca (insns);
3187 #endif
3189 /* Instantiate all virtual registers. */
3190 instantiate_virtual_regs (current_function_decl, insns);
3192 open_dump_file (DFI_jump, decl);
3194 /* Always do one jump optimization pass to ensure that JUMP_LABEL fields
3195 are initialized and to compute whether control can drop off the end
3196 of the function. */
3198 timevar_push (TV_JUMP);
3199 /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this
3200 before jump optimization switches branch directions. */
3201 if (flag_guess_branch_prob)
3202 expected_value_to_br_prob ();
3204 reg_scan (insns, max_reg_num (), 0);
3205 rebuild_jump_labels (insns);
3206 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3207 delete_trivially_dead_insns (insns, max_reg_num ());
3208 if (rtl_dump_file)
3209 dump_flow_info (rtl_dump_file);
3210 cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP
3211 | (flag_thread_jumps ? CLEANUP_THREADING : 0));
3213 if (optimize)
3215 free_bb_for_insn ();
3216 copy_loop_headers (insns);
3217 find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
3219 purge_line_number_notes (insns);
3221 timevar_pop (TV_JUMP);
3222 close_dump_file (DFI_jump, print_rtl, insns);
3224 /* Now is when we stop if -fsyntax-only and -Wreturn-type. */
3225 if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl))
3226 goto exit_rest_of_compilation;
3228 /* Long term, this should probably move before the jump optimizer too,
3229 but I didn't want to disturb the rtl_dump_and_exit and related
3230 stuff at this time. */
3231 if (optimize > 0 && flag_ssa)
3232 insns = rest_of_handle_ssa (decl, insns);
3234 timevar_push (TV_JUMP);
3236 if (optimize)
3237 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
3239 if (flag_delete_null_pointer_checks)
3240 rest_of_handle_null_pointer (decl, insns);
3242 /* Jump optimization, and the removal of NULL pointer checks, may
3243 have reduced the number of instructions substantially. CSE, and
3244 future passes, allocate arrays whose dimensions involve the
3245 maximum instruction UID, so if we can reduce the maximum UID
3246 we'll save big on memory. */
3247 renumber_insns (rtl_dump_file);
3248 timevar_pop (TV_JUMP);
3250 close_dump_file (DFI_jump, print_rtl_with_bb, insns);
3252 ggc_collect ();
3254 if (optimize > 0)
3255 rest_of_handle_cse (decl, insns);
3257 rest_of_handle_addressof (decl, insns);
3259 ggc_collect ();
3261 if (optimize > 0)
3263 if (flag_gcse)
3264 rest_of_handle_gcse (decl, insns);
3266 if (flag_loop_optimize)
3267 rest_of_handle_loop_optimize (decl, insns);
3269 if (flag_gcse)
3270 rest_of_handle_jump_bypass (decl, insns);
3273 timevar_push (TV_FLOW);
3275 rest_of_handle_cfg (decl, insns);
3277 if (optimize > 0
3278 || profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
3279 rest_of_handle_branch_prob (decl, insns);
3281 if (optimize > 0)
3282 rest_of_handle_if_conversion (decl, insns);
3284 if (flag_tracer)
3285 rest_of_handle_tracer (decl, insns);
3287 if (optimize > 0
3288 && (flag_unswitch_loops
3289 || flag_peel_loops
3290 || flag_unroll_loops))
3291 rest_of_handle_loop2 (decl, insns);
3293 if (flag_rerun_cse_after_loop)
3294 rest_of_handle_cse2 (decl, insns);
3296 cse_not_expected = 1;
3298 rest_of_handle_life (decl, insns);
3300 if (optimize > 0)
3301 rest_of_handle_combine (decl, insns);
3303 if (flag_if_conversion)
3304 rest_of_handle_if_after_combine (decl, insns);
3306 if (optimize > 0 && (flag_regmove || flag_expensive_optimizations))
3307 rest_of_handle_regmove (decl, insns);
3309 /* Do unconditional splitting before register allocation to allow machine
3310 description to add extra information not needed previously. */
3311 split_all_insns (1);
3313 #ifdef OPTIMIZE_MODE_SWITCHING
3314 timevar_push (TV_MODE_SWITCH);
3316 no_new_pseudos = 0;
3317 optimize_mode_switching (NULL);
3318 no_new_pseudos = 1;
3320 timevar_pop (TV_MODE_SWITCH);
3321 #endif
3323 /* Any of the several passes since flow1 will have munged register
3324 lifetime data a bit. We need it to be up to date for scheduling
3325 (see handling of reg_known_equiv in init_alias_analysis). */
3326 recompute_reg_usage (insns, !optimize_size);
3328 #ifdef INSN_SCHEDULING
3329 rest_of_handle_sched (decl, insns);
3330 #endif
3332 /* Determine if the current function is a leaf before running reload
3333 since this can impact optimizations done by the prologue and
3334 epilogue thus changing register elimination offsets. */
3335 current_function_is_leaf = leaf_function_p ();
3337 timevar_push (TV_LOCAL_ALLOC);
3338 open_dump_file (DFI_lreg, decl);
3340 if (flag_new_regalloc)
3342 if (rest_of_handle_new_regalloc (decl, insns,
3343 &rebuild_label_notes_after_reload))
3344 goto exit_rest_of_compilation;
3346 else
3348 if (rest_of_handle_old_regalloc (decl, insns,
3349 &rebuild_label_notes_after_reload))
3350 goto exit_rest_of_compilation;
3353 ggc_collect ();
3355 open_dump_file (DFI_postreload, decl);
3357 /* Do a very simple CSE pass over just the hard registers. */
3358 if (optimize > 0)
3360 timevar_push (TV_RELOAD_CSE_REGS);
3361 reload_cse_regs (insns);
3362 timevar_pop (TV_RELOAD_CSE_REGS);
3365 /* Register allocation and reloading may have turned an indirect jump into
3366 a direct jump. If so, we must rebuild the JUMP_LABEL fields of
3367 jumping instructions. */
3368 if (rebuild_label_notes_after_reload)
3370 timevar_push (TV_JUMP);
3372 rebuild_jump_labels (insns);
3373 purge_all_dead_edges (0);
3375 timevar_pop (TV_JUMP);
3378 close_dump_file (DFI_postreload, print_rtl_with_bb, insns);
3380 /* Re-create the death notes which were deleted during reload. */
3381 timevar_push (TV_FLOW2);
3382 open_dump_file (DFI_flow2, decl);
3384 #ifdef ENABLE_CHECKING
3385 verify_flow_info ();
3386 #endif
3388 /* If optimizing, then go ahead and split insns now. */
3389 #ifndef STACK_REGS
3390 if (optimize > 0)
3391 #endif
3392 split_all_insns (0);
3394 if (flag_branch_target_load_optimize)
3396 open_dump_file (DFI_branch_target_load, decl);
3398 branch_target_load_optimize (insns, false);
3400 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3402 ggc_collect ();
3405 if (optimize)
3406 cleanup_cfg (CLEANUP_EXPENSIVE);
3408 /* On some machines, the prologue and epilogue code, or parts thereof,
3409 can be represented as RTL. Doing so lets us schedule insns between
3410 it and the rest of the code and also allows delayed branch
3411 scheduling to operate in the epilogue. */
3412 thread_prologue_and_epilogue_insns (insns);
3413 epilogue_completed = 1;
3415 if (optimize)
3417 life_analysis (insns, rtl_dump_file, PROP_FINAL);
3418 cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE
3419 | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0));
3421 /* This is kind of a heuristic. We need to run combine_stack_adjustments
3422 even for machines with possibly nonzero RETURN_POPS_ARGS
3423 and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having
3424 push instructions will have popping returns. */
3425 #ifndef PUSH_ROUNDING
3426 if (!ACCUMULATE_OUTGOING_ARGS)
3427 #endif
3428 combine_stack_adjustments ();
3430 ggc_collect ();
3433 flow2_completed = 1;
3435 close_dump_file (DFI_flow2, print_rtl_with_bb, insns);
3436 timevar_pop (TV_FLOW2);
3438 #ifdef HAVE_peephole2
3439 if (optimize > 0 && flag_peephole2)
3441 timevar_push (TV_PEEPHOLE2);
3442 open_dump_file (DFI_peephole2, decl);
3444 peephole2_optimize (rtl_dump_file);
3446 close_dump_file (DFI_peephole2, print_rtl_with_bb, insns);
3447 timevar_pop (TV_PEEPHOLE2);
3449 #endif
3451 if (optimize > 0)
3453 if (flag_rename_registers || flag_cprop_registers)
3454 rest_of_handle_regrename (decl, insns);
3456 rest_of_handle_reorder_blocks (decl, insns);
3459 if (flag_if_conversion2)
3461 timevar_push (TV_IFCVT2);
3462 open_dump_file (DFI_ce3, decl);
3464 if_convert (1);
3466 close_dump_file (DFI_ce3, print_rtl_with_bb, insns);
3467 timevar_pop (TV_IFCVT2);
3470 if (flag_branch_target_load_optimize2)
3472 /* Leave this a warning for now so that it is possible to experiment
3473 with running this pass twice. In 3.6, we should either make this
3474 an error, or use separate dump files. */
3475 if (flag_branch_target_load_optimize)
3476 warning ("branch target register load optimization is not intended "
3477 "to be run twice");
3479 open_dump_file (DFI_branch_target_load, decl);
3481 branch_target_load_optimize (insns, true);
3483 close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns);
3485 ggc_collect ();
3488 #ifdef INSN_SCHEDULING
3489 if (optimize > 0 && flag_schedule_insns_after_reload)
3490 rest_of_handle_sched2 (decl, insns);
3491 #endif
3493 #ifdef LEAF_REGISTERS
3494 current_function_uses_only_leaf_regs
3495 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
3496 #endif
3498 #ifdef STACK_REGS
3499 rest_of_handle_stack_regs (decl, insns);
3500 #endif
3502 compute_alignments ();
3504 /* CFG is no longer maintained up-to-date. */
3505 free_bb_for_insn ();
3507 if (targetm.machine_dependent_reorg != 0)
3508 rest_of_handle_machine_reorg (decl, insns);
3510 purge_line_number_notes (insns);
3511 cleanup_barriers ();
3513 #ifdef DELAY_SLOTS
3514 if (optimize > 0 && flag_delayed_branch)
3515 rest_of_handle_delay_slots (decl, insns);
3516 #endif
3518 #if defined (HAVE_ATTR_length) && !defined (STACK_REGS)
3519 timevar_push (TV_SHORTEN_BRANCH);
3520 split_all_insns_noflow ();
3521 timevar_pop (TV_SHORTEN_BRANCH);
3522 #endif
3524 convert_to_eh_region_ranges ();
3526 /* Shorten branches. */
3527 timevar_push (TV_SHORTEN_BRANCH);
3528 shorten_branches (get_insns ());
3529 timevar_pop (TV_SHORTEN_BRANCH);
3531 set_nothrow_function_flags ();
3532 if (current_function_nothrow)
3533 /* Now we know that this can't throw; set the flag for the benefit
3534 of other functions later in this translation unit. */
3535 TREE_NOTHROW (current_function_decl) = 1;
3537 rest_of_handle_final (decl, insns);
3539 /* Write DBX symbols if requested. */
3541 /* Note that for those inline functions where we don't initially
3542 know for certain that we will be generating an out-of-line copy,
3543 the first invocation of this routine (rest_of_compilation) will
3544 skip over this code by doing a `goto exit_rest_of_compilation;'.
3545 Later on, wrapup_global_declarations will (indirectly) call
3546 rest_of_compilation again for those inline functions that need
3547 to have out-of-line copies generated. During that call, we
3548 *will* be routed past here. */
3550 timevar_push (TV_SYMOUT);
3551 (*debug_hooks->function_decl) (decl);
3552 timevar_pop (TV_SYMOUT);
3554 exit_rest_of_compilation:
3556 coverage_end_function ();
3558 /* In case the function was not output,
3559 don't leave any temporary anonymous types
3560 queued up for sdb output. */
3561 #ifdef SDB_DEBUGGING_INFO
3562 if (write_symbols == SDB_DEBUG)
3563 sdbout_types (NULL_TREE);
3564 #endif
3566 reload_completed = 0;
3567 epilogue_completed = 0;
3568 flow2_completed = 0;
3569 no_new_pseudos = 0;
3571 timevar_push (TV_FINAL);
3573 /* Clear out the insn_length contents now that they are no
3574 longer valid. */
3575 init_insn_lengths ();
3577 /* Show no temporary slots allocated. */
3578 init_temp_slots ();
3580 free_basic_block_vars (0);
3581 free_bb_for_insn ();
3583 timevar_pop (TV_FINAL);
3585 if ((*targetm.binds_local_p) (current_function_decl))
3587 int pref = cfun->preferred_stack_boundary;
3588 if (cfun->recursive_call_emit
3589 && cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
3590 pref = cfun->stack_alignment_needed;
3591 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
3592 = pref;
3595 /* Make sure volatile mem refs aren't considered valid operands for
3596 arithmetic insns. We must call this here if this is a nested inline
3597 function, since the above code leaves us in the init_recog state
3598 (from final.c), and the function context push/pop code does not
3599 save/restore volatile_ok.
3601 ??? Maybe it isn't necessary for expand_start_function to call this
3602 anymore if we do it here? */
3604 init_recog_no_volatile ();
3606 /* We're done with this function. Free up memory if we can. */
3607 free_after_parsing (cfun);
3608 if (! DECL_DEFER_OUTPUT (decl))
3610 free_after_compilation (cfun);
3612 /* Clear integrate.c's pointer to the cfun structure we just
3613 destroyed. */
3614 DECL_SAVED_INSNS (decl) = 0;
3616 cfun = 0;
3618 ggc_collect ();
3620 timevar_pop (TV_REST_OF_COMPILATION);
3623 /* Display help for generic options. */
3624 void
3625 display_help (void)
3627 unsigned long i;
3629 for (i = ARRAY_SIZE (debug_args); i--;)
3631 if (debug_args[i].description != NULL)
3632 printf (" -g%-21s %s\n",
3633 debug_args[i].arg, _(debug_args[i].description));
3636 display_target_options ();
3639 /* Display help for target options. */
3640 void
3641 display_target_options (void)
3643 int undoc, i;
3644 static bool displayed = false;
3646 /* Avoid double printing for --help --target-help. */
3647 if (displayed)
3648 return;
3650 displayed = true;
3652 if (ARRAY_SIZE (target_switches) > 1
3653 #ifdef TARGET_OPTIONS
3654 || ARRAY_SIZE (target_options) > 1
3655 #endif
3658 int doc = 0;
3660 undoc = 0;
3662 printf (_("\nTarget specific options:\n"));
3664 for (i = ARRAY_SIZE (target_switches); i--;)
3666 const char *option = target_switches[i].name;
3667 const char *description = target_switches[i].description;
3669 if (option == NULL || *option == 0)
3670 continue;
3671 else if (description == NULL)
3673 undoc = 1;
3675 if (extra_warnings)
3676 printf (_(" -m%-23s [undocumented]\n"), option);
3678 else if (*description != 0)
3679 doc += printf (" -m%-23s %s\n", option, _(description));
3682 #ifdef TARGET_OPTIONS
3683 for (i = ARRAY_SIZE (target_options); i--;)
3685 const char *option = target_options[i].prefix;
3686 const char *description = target_options[i].description;
3688 if (option == NULL || *option == 0)
3689 continue;
3690 else if (description == NULL)
3692 undoc = 1;
3694 if (extra_warnings)
3695 printf (_(" -m%-23s [undocumented]\n"), option);
3697 else if (*description != 0)
3698 doc += printf (" -m%-23s %s\n", option, _(description));
3700 #endif
3701 if (undoc)
3703 if (doc)
3704 printf (_("\nThere are undocumented target specific options as well.\n"));
3705 else
3706 printf (_(" They exist, but they are not documented.\n"));
3711 /* Parse a -d... command line switch. */
3713 void
3714 decode_d_option (const char *arg)
3716 int i, c, matched;
3718 while (*arg)
3719 switch (c = *arg++)
3721 case 'a':
3722 for (i = 0; i < (int) DFI_MAX; ++i)
3723 dump_file[i].enabled = 1;
3724 break;
3725 case 'A':
3726 flag_debug_asm = 1;
3727 break;
3728 case 'p':
3729 flag_print_asm_name = 1;
3730 break;
3731 case 'P':
3732 flag_dump_rtl_in_asm = 1;
3733 flag_print_asm_name = 1;
3734 break;
3735 case 'v':
3736 graph_dump_format = vcg;
3737 break;
3738 case 'x':
3739 rtl_dump_and_exit = 1;
3740 break;
3741 case 'y':
3742 set_yydebug = 1;
3743 break;
3744 case 'D': /* These are handled by the preprocessor. */
3745 case 'I':
3746 break;
3747 case 'H':
3748 setup_core_dumping();
3749 break;
3751 default:
3752 matched = 0;
3753 for (i = 0; i < (int) DFI_MAX; ++i)
3754 if (c == dump_file[i].debug_switch)
3756 dump_file[i].enabled = 1;
3757 matched = 1;
3760 if (! matched)
3761 warning ("unrecognized gcc debugging option: %c", c);
3762 break;
3766 /* Indexed by enum debug_info_type. */
3767 const char *const debug_type_names[] =
3769 "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff", "vms"
3772 /* Parse a -g... command line switch. ARG is the value after the -g.
3773 It is safe to access 'ARG - 2' to generate the full switch name.
3774 Return the number of strings consumed. */
3776 void
3777 decode_g_option (const char *arg)
3779 static unsigned level = 0;
3780 /* A lot of code assumes write_symbols == NO_DEBUG if the
3781 debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
3782 of what debugging type has been selected). This records the
3783 selected type. It is an error to specify more than one
3784 debugging type. */
3785 static enum debug_info_type selected_debug_type = NO_DEBUG;
3786 /* Nonzero if debugging format has been explicitly set.
3787 -g and -ggdb don't explicitly set the debugging format so
3788 -gdwarf -g3 is equivalent to -gdwarf3. */
3789 static int type_explicitly_set_p = 0;
3791 /* The maximum admissible debug level value. */
3792 static const unsigned max_debug_level = 3;
3794 /* Look up ARG in the table. */
3795 for (da = debug_args; da->arg; da++)
3797 const int da_len = strlen (da->arg);
3799 if (da_len == 0 || ! strncmp (arg, da->arg, da_len))
3801 enum debug_info_type type = da->debug_type;
3802 const char *p = arg + da_len;
3804 if (*p && ! ISDIGIT (*p))
3805 continue;
3807 /* A debug flag without a level defaults to level 2.
3808 Note we do not want to call read_integral_parameter
3809 for that case since it will call atoi which
3810 will return zero.
3812 ??? We may want to generalize the interface to
3813 read_integral_parameter to better handle this case
3814 if this case shows up often. */
3815 if (*p)
3816 level = read_integral_parameter (p, 0, max_debug_level + 1);
3817 else
3818 level = (level == 0) ? 2 : level;
3820 if (da_len > 1 && *p && !strncmp (arg, "dwarf", da_len))
3822 error ("use -gdwarf -g%d for DWARF v1, level %d",
3823 level, level);
3824 if (level == 2)
3825 error ("use -gdwarf-2 for DWARF v2");
3828 if (level > max_debug_level)
3830 warning ("\
3831 ignoring option `%s' due to invalid debug level specification",
3832 arg - 2);
3833 level = debug_info_level;
3836 if (type == NO_DEBUG)
3838 type = PREFERRED_DEBUGGING_TYPE;
3840 if (da_len > 1 && strncmp (arg, "gdb", da_len) == 0)
3842 #ifdef DWARF2_DEBUGGING_INFO
3843 type = DWARF2_DEBUG;
3844 #else
3845 #ifdef DBX_DEBUGGING_INFO
3846 type = DBX_DEBUG;
3847 #endif
3848 #endif
3852 if (type == NO_DEBUG)
3853 warning ("`%s': unknown or unsupported -g option", arg - 2);
3855 /* Does it conflict with an already selected type? */
3856 if (type_explicitly_set_p
3857 /* -g/-ggdb don't conflict with anything. */
3858 && da->debug_type != NO_DEBUG
3859 && type != selected_debug_type)
3860 warning ("`%s' ignored, conflicts with `-g%s'",
3861 arg - 2, debug_type_names[(int) selected_debug_type]);
3862 else
3864 /* If the format has already been set, -g/-ggdb
3865 only change the debug level. */
3866 if (type_explicitly_set_p && da->debug_type == NO_DEBUG)
3867 /* Don't change debugging type. */
3869 else
3871 selected_debug_type = type;
3872 type_explicitly_set_p = da->debug_type != NO_DEBUG;
3875 write_symbols = (level == 0
3876 ? NO_DEBUG
3877 : selected_debug_type);
3878 use_gnu_debug_info_extensions = da->use_extensions_p;
3879 debug_info_level = (enum debug_info_level) level;
3882 break;
3886 if (! da->arg)
3887 warning ("`-g%s': unknown or unsupported -g option", arg);
3890 /* Decode -m switches. */
3891 /* Decode the switch -mNAME. */
3893 void
3894 set_target_switch (const char *name)
3896 size_t j;
3897 int valid_target_option = 0;
3899 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
3900 if (!strcmp (target_switches[j].name, name))
3902 if (target_switches[j].value < 0)
3903 target_flags &= ~-target_switches[j].value;
3904 else
3905 target_flags |= target_switches[j].value;
3906 if (name[0] != 0)
3908 if (target_switches[j].value < 0)
3909 target_flags_explicit |= -target_switches[j].value;
3910 else
3911 target_flags_explicit |= target_switches[j].value;
3913 valid_target_option = 1;
3916 #ifdef TARGET_OPTIONS
3917 if (!valid_target_option)
3918 for (j = 0; j < ARRAY_SIZE (target_options); j++)
3920 int len = strlen (target_options[j].prefix);
3921 if (target_options[j].value)
3923 if (!strcmp (target_options[j].prefix, name))
3925 *target_options[j].variable = target_options[j].value;
3926 valid_target_option = 1;
3929 else
3931 if (!strncmp (target_options[j].prefix, name, len))
3933 *target_options[j].variable = name + len;
3934 valid_target_option = 1;
3938 #endif
3940 if (!valid_target_option)
3941 error ("invalid option `%s'", name);
3944 /* Print version information to FILE.
3945 Each line begins with INDENT (for the case where FILE is the
3946 assembler output file). */
3948 void
3949 print_version (FILE *file, const char *indent)
3951 #ifndef __VERSION__
3952 #define __VERSION__ "[?]"
3953 #endif
3954 fnotice (file,
3955 #ifdef __GNUC__
3956 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
3957 #else
3958 "%s%s%s version %s (%s) compiled by CC.\n"
3959 #endif
3960 , indent, *indent != 0 ? " " : "",
3961 lang_hooks.name, version_string, TARGET_NAME,
3962 indent, __VERSION__);
3963 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
3964 indent, *indent != 0 ? " " : "",
3965 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
3968 /* Print an option value and return the adjusted position in the line.
3969 ??? We don't handle error returns from fprintf (disk full); presumably
3970 other code will catch a disk full though. */
3972 static int
3973 print_single_switch (FILE *file, int pos, int max,
3974 const char *indent, const char *sep, const char *term,
3975 const char *type, const char *name)
3977 /* The ultrix fprintf returns 0 on success, so compute the result we want
3978 here since we need it for the following test. */
3979 int len = strlen (sep) + strlen (type) + strlen (name);
3981 if (pos != 0
3982 && pos + len > max)
3984 fprintf (file, "%s", term);
3985 pos = 0;
3987 if (pos == 0)
3989 fprintf (file, "%s", indent);
3990 pos = strlen (indent);
3992 fprintf (file, "%s%s%s", sep, type, name);
3993 pos += len;
3994 return pos;
3997 /* Print active target switches to FILE.
3998 POS is the current cursor position and MAX is the size of a "line".
3999 Each line begins with INDENT and ends with TERM.
4000 Each switch is separated from the next by SEP. */
4002 static void
4003 print_switch_values (FILE *file, int pos, int max,
4004 const char *indent, const char *sep, const char *term)
4006 size_t j;
4007 const char **p;
4009 /* Fill in the -frandom-seed option, if the user didn't pass it, so
4010 that it can be printed below. This helps reproducibility. */
4011 randomize ();
4013 /* Print the options as passed. */
4014 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
4015 _("options passed: "), "");
4017 for (p = &save_argv[1]; *p != NULL; p++)
4018 if (**p == '-')
4020 /* Ignore these. */
4021 if (strcmp (*p, "-o") == 0)
4023 if (p[1] != NULL)
4024 p++;
4025 continue;
4027 if (strcmp (*p, "-quiet") == 0)
4028 continue;
4029 if (strcmp (*p, "-version") == 0)
4030 continue;
4031 if ((*p)[1] == 'd')
4032 continue;
4034 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
4036 if (pos > 0)
4037 fprintf (file, "%s", term);
4039 /* Print the -f and -m options that have been enabled.
4040 We don't handle language specific options but printing argv
4041 should suffice. */
4043 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
4044 _("options enabled: "), "");
4046 for (j = 0; j < ARRAY_SIZE (f_options); j++)
4047 if (*f_options[j].variable == f_options[j].on_value)
4048 pos = print_single_switch (file, pos, max, indent, sep, term,
4049 "-f", f_options[j].string);
4051 /* Print target specific options. */
4053 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
4054 if (target_switches[j].name[0] != '\0'
4055 && target_switches[j].value > 0
4056 && ((target_switches[j].value & target_flags)
4057 == target_switches[j].value))
4059 pos = print_single_switch (file, pos, max, indent, sep, term,
4060 "-m", target_switches[j].name);
4063 #ifdef TARGET_OPTIONS
4064 for (j = 0; j < ARRAY_SIZE (target_options); j++)
4065 if (*target_options[j].variable != NULL)
4067 char prefix[256];
4068 sprintf (prefix, "-m%s", target_options[j].prefix);
4069 pos = print_single_switch (file, pos, max, indent, sep, term,
4070 prefix, *target_options[j].variable);
4072 #endif
4074 fprintf (file, "%s", term);
4077 /* Open assembly code output file. Do this even if -fsyntax-only is
4078 on, because then the driver will have provided the name of a
4079 temporary file or bit bucket for us. NAME is the file specified on
4080 the command line, possibly NULL. */
4081 static void
4082 init_asm_output (const char *name)
4084 if (name == NULL && asm_file_name == 0)
4085 asm_out_file = stdout;
4086 else
4088 if (asm_file_name == 0)
4090 int len = strlen (dump_base_name);
4091 char *dumpname = xmalloc (len + 6);
4092 memcpy (dumpname, dump_base_name, len + 1);
4093 strip_off_ending (dumpname, len);
4094 strcat (dumpname, ".s");
4095 asm_file_name = dumpname;
4097 if (!strcmp (asm_file_name, "-"))
4098 asm_out_file = stdout;
4099 else
4100 asm_out_file = fopen (asm_file_name, "w+");
4101 if (asm_out_file == 0)
4102 fatal_error ("can't open %s for writing: %m", asm_file_name);
4105 #ifdef IO_BUFFER_SIZE
4106 setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE),
4107 _IOFBF, IO_BUFFER_SIZE);
4108 #endif
4110 if (!flag_syntax_only)
4112 targetm.asm_out.file_start ();
4114 #ifdef ASM_COMMENT_START
4115 if (flag_verbose_asm)
4117 /* Print the list of options in effect. */
4118 print_version (asm_out_file, ASM_COMMENT_START);
4119 print_switch_values (asm_out_file, 0, MAX_LINE,
4120 ASM_COMMENT_START, " ", "\n");
4121 /* Add a blank line here so it appears in assembler output but not
4122 screen output. */
4123 fprintf (asm_out_file, "\n");
4125 #endif
4129 /* Default tree printer. Handles declarations only. */
4130 static bool
4131 default_tree_printer (pretty_printer * pp, text_info *text)
4133 switch (*text->format_spec)
4135 case 'D':
4136 case 'F':
4137 case 'T':
4139 tree t = va_arg (*text->args_ptr, tree);
4140 const char *n = DECL_NAME (t)
4141 ? (*lang_hooks.decl_printable_name) (t, 2)
4142 : "<anonymous>";
4143 pp_string (pp, n);
4145 return true;
4147 default:
4148 return false;
4152 /* Initialization of the front end environment, before command line
4153 options are parsed. Signal handlers, internationalization etc.
4154 ARGV0 is main's argv[0]. */
4155 static void
4156 general_init (const char *argv0)
4158 const char *p;
4160 p = argv0 + strlen (argv0);
4161 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
4162 --p;
4163 progname = p;
4165 xmalloc_set_program_name (progname);
4167 hex_init ();
4169 gcc_init_libintl ();
4171 /* Initialize the diagnostics reporting machinery, so option parsing
4172 can give warnings and errors. */
4173 diagnostic_initialize (global_dc);
4174 /* Set a default printer. Language specific initializations will
4175 override it later. */
4176 pp_format_decoder (global_dc->printer) = &default_tree_printer;
4178 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
4179 #ifdef SIGSEGV
4180 signal (SIGSEGV, crash_signal);
4181 #endif
4182 #ifdef SIGILL
4183 signal (SIGILL, crash_signal);
4184 #endif
4185 #ifdef SIGBUS
4186 signal (SIGBUS, crash_signal);
4187 #endif
4188 #ifdef SIGABRT
4189 signal (SIGABRT, crash_signal);
4190 #endif
4191 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
4192 signal (SIGIOT, crash_signal);
4193 #endif
4194 #ifdef SIGFPE
4195 signal (SIGFPE, crash_signal);
4196 #endif
4198 /* Other host-specific signal setup. */
4199 (*host_hooks.extra_signals)();
4201 /* Initialize the garbage-collector, string pools and tree type hash
4202 table. */
4203 init_ggc ();
4204 init_stringpool ();
4205 init_ttree ();
4207 /* Initialize register usage now so switches may override. */
4208 init_reg_sets ();
4210 /* Register the language-independent parameters. */
4211 add_params (lang_independent_params, LAST_PARAM);
4213 /* This must be done after add_params but before argument processing. */
4214 init_ggc_heuristics();
4217 /* Process the options that have been parsed. */
4218 static void
4219 process_options (void)
4221 /* Allow the front end to perform consistency checks and do further
4222 initialization based on the command line options. This hook also
4223 sets the original filename if appropriate (e.g. foo.i -> foo.c)
4224 so we can correctly initialize debug output. */
4225 no_backend = (*lang_hooks.post_options) (&main_input_filename);
4226 input_filename = main_input_filename;
4228 #ifdef OVERRIDE_OPTIONS
4229 /* Some machines may reject certain combinations of options. */
4230 OVERRIDE_OPTIONS;
4231 #endif
4233 /* Set aux_base_name if not already set. */
4234 if (aux_base_name)
4236 else if (main_input_filename)
4238 char *name = xstrdup (lbasename (main_input_filename));
4240 strip_off_ending (name, strlen (name));
4241 aux_base_name = name;
4243 else
4244 aux_base_name = "gccaux";
4246 /* Set up the align_*_log variables, defaulting them to 1 if they
4247 were still unset. */
4248 if (align_loops <= 0) align_loops = 1;
4249 if (align_loops_max_skip > align_loops || !align_loops)
4250 align_loops_max_skip = align_loops - 1;
4251 align_loops_log = floor_log2 (align_loops * 2 - 1);
4252 if (align_jumps <= 0) align_jumps = 1;
4253 if (align_jumps_max_skip > align_jumps || !align_jumps)
4254 align_jumps_max_skip = align_jumps - 1;
4255 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
4256 if (align_labels <= 0) align_labels = 1;
4257 align_labels_log = floor_log2 (align_labels * 2 - 1);
4258 if (align_labels_max_skip > align_labels || !align_labels)
4259 align_labels_max_skip = align_labels - 1;
4260 if (align_functions <= 0) align_functions = 1;
4261 align_functions_log = floor_log2 (align_functions * 2 - 1);
4263 /* Unrolling all loops implies that standard loop unrolling must also
4264 be done. */
4265 if (flag_unroll_all_loops)
4266 flag_unroll_loops = 1;
4268 if (flag_unroll_loops)
4270 flag_old_unroll_loops = 0;
4271 flag_old_unroll_all_loops = 0;
4274 if (flag_old_unroll_all_loops)
4275 flag_old_unroll_loops = 1;
4277 /* Old loop unrolling requires that strength_reduction be on also. Silently
4278 turn on strength reduction here if it isn't already on. Also, the loop
4279 unrolling code assumes that cse will be run after loop, so that must
4280 be turned on also. */
4281 if (flag_old_unroll_loops)
4283 flag_strength_reduce = 1;
4284 flag_rerun_cse_after_loop = 1;
4286 if (flag_unroll_loops || flag_peel_loops)
4287 flag_rerun_cse_after_loop = 1;
4289 if (flag_non_call_exceptions)
4290 flag_asynchronous_unwind_tables = 1;
4291 if (flag_asynchronous_unwind_tables)
4292 flag_unwind_tables = 1;
4294 /* Disable unit-at-a-time mode for frontends not supporting callgraph
4295 interface. */
4296 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
4297 flag_unit_at_a_time = 0;
4299 /* Warn about options that are not supported on this machine. */
4300 #ifndef INSN_SCHEDULING
4301 if (flag_schedule_insns || flag_schedule_insns_after_reload)
4302 warning ("instruction scheduling not supported on this target machine");
4303 #endif
4304 #ifndef DELAY_SLOTS
4305 if (flag_delayed_branch)
4306 warning ("this target machine does not have delayed branches");
4307 #endif
4309 user_label_prefix = USER_LABEL_PREFIX;
4310 if (flag_leading_underscore != -1)
4312 /* If the default prefix is more complicated than "" or "_",
4313 issue a warning and ignore this option. */
4314 if (user_label_prefix[0] == 0 ||
4315 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
4317 user_label_prefix = flag_leading_underscore ? "_" : "";
4319 else
4320 warning ("-f%sleading-underscore not supported on this target machine",
4321 flag_leading_underscore ? "" : "no-");
4324 /* If we are in verbose mode, write out the version and maybe all the
4325 option flags in use. */
4326 if (version_flag)
4328 print_version (stderr, "");
4329 if (! quiet_flag)
4330 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
4333 if (flag_syntax_only)
4335 write_symbols = NO_DEBUG;
4336 profile_flag = 0;
4339 /* Now we know write_symbols, set up the debug hooks based on it.
4340 By default we do nothing for debug output. */
4341 #if defined(DBX_DEBUGGING_INFO)
4342 if (write_symbols == DBX_DEBUG)
4343 debug_hooks = &dbx_debug_hooks;
4344 #endif
4345 #if defined(XCOFF_DEBUGGING_INFO)
4346 if (write_symbols == XCOFF_DEBUG)
4347 debug_hooks = &xcoff_debug_hooks;
4348 #endif
4349 #ifdef SDB_DEBUGGING_INFO
4350 if (write_symbols == SDB_DEBUG)
4351 debug_hooks = &sdb_debug_hooks;
4352 #endif
4353 #ifdef DWARF_DEBUGGING_INFO
4354 if (write_symbols == DWARF_DEBUG)
4355 debug_hooks = &dwarf_debug_hooks;
4356 #endif
4357 #ifdef DWARF2_DEBUGGING_INFO
4358 if (write_symbols == DWARF2_DEBUG)
4359 debug_hooks = &dwarf2_debug_hooks;
4360 #endif
4361 #ifdef VMS_DEBUGGING_INFO
4362 if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
4363 debug_hooks = &vmsdbg_debug_hooks;
4364 #endif
4366 /* If auxiliary info generation is desired, open the output file.
4367 This goes in the same directory as the source file--unlike
4368 all the other output files. */
4369 if (flag_gen_aux_info)
4371 aux_info_file = fopen (aux_info_file_name, "w");
4372 if (aux_info_file == 0)
4373 fatal_error ("can't open %s: %m", aux_info_file_name);
4376 if (! targetm.have_named_sections)
4378 if (flag_function_sections)
4380 warning ("-ffunction-sections not supported for this target");
4381 flag_function_sections = 0;
4383 if (flag_data_sections)
4385 warning ("-fdata-sections not supported for this target");
4386 flag_data_sections = 0;
4390 if (flag_function_sections && profile_flag)
4392 warning ("-ffunction-sections disabled; it makes profiling impossible");
4393 flag_function_sections = 0;
4396 #ifndef HAVE_prefetch
4397 if (flag_prefetch_loop_arrays)
4399 warning ("-fprefetch-loop-arrays not supported for this target");
4400 flag_prefetch_loop_arrays = 0;
4402 #else
4403 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
4405 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
4406 flag_prefetch_loop_arrays = 0;
4408 #endif
4410 /* This combination of options isn't handled for i386 targets and doesn't
4411 make much sense anyway, so don't allow it. */
4412 if (flag_prefetch_loop_arrays && optimize_size)
4414 warning ("-fprefetch-loop-arrays is not supported with -Os");
4415 flag_prefetch_loop_arrays = 0;
4418 #ifndef OBJECT_FORMAT_ELF
4419 if (flag_function_sections && write_symbols != NO_DEBUG)
4420 warning ("-ffunction-sections may affect debugging on some targets");
4421 #endif
4423 /* The presence of IEEE signaling NaNs, implies all math can trap. */
4424 if (flag_signaling_nans)
4425 flag_trapping_math = 1;
4428 /* Initialize the compiler back end. */
4429 static void
4430 backend_init (void)
4432 /* init_emit_once uses reg_raw_mode and therefore must be called
4433 after init_regs which initialized reg_raw_mode. */
4434 init_regs ();
4435 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
4436 || debug_info_level == DINFO_LEVEL_VERBOSE
4437 #ifdef VMS_DEBUGGING_INFO
4438 /* Enable line number info for traceback. */
4439 || debug_info_level > DINFO_LEVEL_NONE
4440 #endif
4441 || flag_test_coverage
4442 || warn_notreached);
4443 init_fake_stack_mems ();
4444 init_alias_once ();
4445 init_loop ();
4446 init_reload ();
4447 init_function_once ();
4448 init_varasm_once ();
4450 /* The following initialization functions need to generate rtl, so
4451 provide a dummy function context for them. */
4452 init_dummy_function_start ();
4453 init_expmed ();
4454 if (flag_caller_saves)
4455 init_caller_save ();
4456 expand_dummy_function_end ();
4459 /* Language-dependent initialization. Returns nonzero on success. */
4460 static int
4461 lang_dependent_init (const char *name)
4463 if (dump_base_name == 0)
4464 dump_base_name = name ? name : "gccdump";
4466 /* Other front-end initialization. */
4467 if ((*lang_hooks.init) () == 0)
4468 return 0;
4470 init_asm_output (name);
4472 /* These create various _DECL nodes, so need to be called after the
4473 front end is initialized. */
4474 init_eh ();
4475 init_optabs ();
4477 /* The following initialization functions need to generate rtl, so
4478 provide a dummy function context for them. */
4479 init_dummy_function_start ();
4480 init_expr_once ();
4481 expand_dummy_function_end ();
4483 /* If dbx symbol table desired, initialize writing it and output the
4484 predefined types. */
4485 timevar_push (TV_SYMOUT);
4487 #ifdef DWARF2_UNWIND_INFO
4488 if (dwarf2out_do_frame ())
4489 dwarf2out_frame_init ();
4490 #endif
4492 /* Now we have the correct original filename, we can initialize
4493 debug output. */
4494 (*debug_hooks->init) (name);
4496 timevar_pop (TV_SYMOUT);
4498 return 1;
4501 /* Clean up: close opened files, etc. */
4503 static void
4504 finalize (void)
4506 /* Close the dump files. */
4507 if (flag_gen_aux_info)
4509 fclose (aux_info_file);
4510 if (errorcount)
4511 unlink (aux_info_file_name);
4514 /* Close non-debugging input and output files. Take special care to note
4515 whether fclose returns an error, since the pages might still be on the
4516 buffer chain while the file is open. */
4518 if (asm_out_file)
4520 if (ferror (asm_out_file) != 0)
4521 fatal_error ("error writing to %s: %m", asm_file_name);
4522 if (fclose (asm_out_file) != 0)
4523 fatal_error ("error closing %s: %m", asm_file_name);
4526 /* Do whatever is necessary to finish printing the graphs. */
4527 if (graph_dump_format != no_graph)
4529 int i;
4531 for (i = 0; i < (int) DFI_MAX; ++i)
4532 if (dump_file[i].initialized && dump_file[i].graph_dump_p)
4534 char seq[16];
4535 char *suffix;
4537 sprintf (seq, DUMPFILE_FORMAT, i);
4538 suffix = concat (seq, dump_file[i].extension, NULL);
4539 finish_graph_dump_file (dump_base_name, suffix);
4540 free (suffix);
4544 if (mem_report)
4546 ggc_print_statistics ();
4547 stringpool_statistics ();
4548 dump_tree_statistics ();
4551 /* Free up memory for the benefit of leak detectors. */
4552 free_reg_info ();
4554 /* Language-specific end of compilation actions. */
4555 (*lang_hooks.finish) ();
4558 /* Initialize the compiler, and compile the input file. */
4559 static void
4560 do_compile (void)
4562 /* Initialize timing first. The C front ends read the main file in
4563 the post_options hook, and C++ does file timings. */
4564 if (time_report || !quiet_flag || flag_detailed_statistics)
4565 timevar_init ();
4566 timevar_start (TV_TOTAL);
4568 process_options ();
4570 /* Don't do any more if an error has already occurred. */
4571 if (!errorcount)
4573 /* Set up the back-end if requested. */
4574 if (!no_backend)
4575 backend_init ();
4577 /* Language-dependent initialization. Returns true on success. */
4578 if (lang_dependent_init (main_input_filename))
4580 if (flag_unit_at_a_time)
4582 open_dump_file (DFI_cgraph, NULL);
4583 cgraph_dump_file = rtl_dump_file;
4584 rtl_dump_file = NULL;
4587 compile_file ();
4589 if (flag_unit_at_a_time)
4591 rtl_dump_file = cgraph_dump_file;
4592 cgraph_dump_file = NULL;
4593 close_dump_file (DFI_cgraph, NULL, NULL_RTX);
4597 finalize ();
4600 /* Stop timing and print the times. */
4601 timevar_stop (TV_TOTAL);
4602 timevar_print (stderr);
4605 /* Entry point of cc1, cc1plus, jc1, f771, etc.
4606 Decode command args, then call compile_file.
4607 Exit code is FATAL_EXIT_CODE if can't open files or if there were
4608 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
4610 It is not safe to call this function more than once. */
4613 toplev_main (unsigned int argc, const char **argv)
4615 save_argv = argv;
4617 /* Initialization of GCC's environment, and diagnostics. */
4618 general_init (argv[0]);
4620 /* Parse the options and do minimal processing; basically just
4621 enough to default flags appropriately. */
4622 decode_options (argc, argv);
4624 randomize ();
4626 /* Exit early if we can (e.g. -help). */
4627 if (!exit_after_options)
4628 do_compile ();
4630 if (errorcount || sorrycount)
4631 return (FATAL_EXIT_CODE);
4633 return (SUCCESS_EXIT_CODE);