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