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