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