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