]>
Commit | Line | Data |
---|---|---|
5e6908ea | 1 | /* Top level of GCC compilers (cc1, cc1plus, etc.) |
4559fd9e | 2 | Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
223b87b6 | 3 | 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
4291d9c8 | 4 | |
1322177d | 5 | This file is part of GCC. |
4291d9c8 | 6 | |
1322177d LB |
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. | |
4291d9c8 | 11 | |
1322177d LB |
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. | |
4291d9c8 RS |
16 | |
17 | You should have received a copy of the GNU General Public License | |
1322177d LB |
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. */ | |
4291d9c8 | 21 | |
4291d9c8 RS |
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" | |
670ee920 KG |
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" | |
4977bab6 ZW |
31 | #include "coretypes.h" |
32 | #include "tm.h" | |
4291d9c8 | 33 | #include <signal.h> |
956d6950 JL |
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> | |
eb910b5a | 41 | #endif |
4291d9c8 RS |
42 | |
43 | #include "input.h" | |
44 | #include "tree.h" | |
4291d9c8 | 45 | #include "rtl.h" |
6baf1cc8 | 46 | #include "tm_p.h" |
4291d9c8 RS |
47 | #include "flags.h" |
48 | #include "insn-attr.h" | |
e5e809f4 | 49 | #include "insn-config.h" |
0dd0e980 | 50 | #include "insn-flags.h" |
23280139 | 51 | #include "hard-reg-set.h" |
e5e809f4 | 52 | #include "recog.h" |
e14417fa | 53 | #include "output.h" |
3d195391 | 54 | #include "except.h" |
49ad7cfa | 55 | #include "function.h" |
a0c8e1b2 | 56 | #include "toplev.h" |
114791ea | 57 | #include "expr.h" |
b1eeb243 | 58 | #include "basic-block.h" |
ab87f8c8 | 59 | #include "intl.h" |
0a25f1f5 | 60 | #include "ggc.h" |
6a2cc2ac | 61 | #include "graph.h" |
272df862 | 62 | #include "loop.h" |
d0af450d | 63 | #include "regs.h" |
2a9a326b | 64 | #include "timevar.h" |
764dbbf2 | 65 | #include "diagnostic.h" |
b53978a3 | 66 | #include "ssa.h" |
c6d9a88c | 67 | #include "params.h" |
8461e984 | 68 | #include "reload.h" |
5262d6b6 | 69 | #include "dwarf2asm.h" |
c0e7830f | 70 | #include "integrate.h" |
efdc7e19 | 71 | #include "real.h" |
a51d908e | 72 | #include "debug.h" |
7c262518 | 73 | #include "target.h" |
d23c55c2 | 74 | #include "langhooks.h" |
0478a14c | 75 | #include "cfglayout.h" |
3d436d2a | 76 | #include "cfgloop.h" |
476d9098 | 77 | #include "hosthooks.h" |
b255a036 | 78 | #include "cgraph.h" |
2772ef3e | 79 | #include "opts.h" |
5b0e2409 | 80 | #include "coverage.h" |
fca9dc00 | 81 | #include "value-prof.h" |
f246a305 | 82 | |
76ead72b RL |
83 | #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO) |
84 | #include "dwarf2out.h" | |
85 | #endif | |
86 | ||
4f70758f | 87 | #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) |
76ead72b RL |
88 | #include "dbxout.h" |
89 | #endif | |
90 | ||
91 | #ifdef SDB_DEBUGGING_INFO | |
92 | #include "sdbout.h" | |
93 | #endif | |
440aabf8 NB |
94 | |
95 | #ifdef XCOFF_DEBUGGING_INFO | |
96 | #include "xcoffout.h" /* Needed for external data | |
97 | declarations for e.g. AIX 4.x. */ | |
98 | #endif | |
ddc9542b | 99 | |
b0316e35 RS |
100 | /* Carry information from ASM_DECLARE_OBJECT_NAME |
101 | to ASM_FINISH_DECLARE_OBJECT. */ | |
102 | ||
103 | extern int size_directive_output; | |
5e10b3cc | 104 | extern tree last_assemble_variable_decl; |
b0316e35 | 105 | |
e25a75e6 AJ |
106 | extern void reg_alloc (void); |
107 | ||
b86f6cd9 | 108 | static void general_init (const char *); |
e25a75e6 AJ |
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 | ||
e25a75e6 AJ |
116 | static void crash_signal (int) ATTRIBUTE_NORETURN; |
117 | static void setup_core_dumping (void); | |
118 | static void compile_file (void); | |
e25a75e6 | 119 | |
e25a75e6 AJ |
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 *); | |
735a0e33 | 125 | |
ddc9542b AH |
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); | |
f129791c | 138 | static void rest_of_handle_addressof (tree, rtx); |
ddc9542b AH |
139 | static void rest_of_handle_cfg (tree, rtx); |
140 | static void rest_of_handle_branch_prob (tree, rtx); | |
fca9dc00 | 141 | static void rest_of_handle_value_profile_transformations (tree, rtx); |
ddc9542b AH |
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); | |
ddc9542b | 147 | #ifdef INSN_SCHEDULING |
a2f8629a | 148 | static void rest_of_handle_sched (tree, rtx); |
ddc9542b AH |
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 | ||
ff45c01e NB |
164 | /* Nonzero to dump debug info whilst parsing (-dy option). */ |
165 | static int set_yydebug; | |
166 | ||
4bfec483 NB |
167 | /* True if we don't need a backend (e.g. preprocessing only). */ |
168 | static bool no_backend; | |
169 | ||
3d5cdd42 DE |
170 | /* Length of line when printing switch values. */ |
171 | #define MAX_LINE 75 | |
172 | ||
4291d9c8 RS |
173 | /* Name of program invoked, sans directories. */ |
174 | ||
7adfcfed | 175 | const char *progname; |
4291d9c8 | 176 | |
b86f6cd9 NB |
177 | /* Copy of argument vector to toplev_main. */ |
178 | static const char **save_argv; | |
ddc9542b | 179 | |
4291d9c8 RS |
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 | ||
3b304f5b | 184 | const char *main_input_filename; |
4291d9c8 | 185 | |
6060edcb | 186 | /* Current position in real source file. */ |
4291d9c8 | 187 | |
6060edcb | 188 | location_t input_location; |
4291d9c8 | 189 | |
f1db3576 JL |
190 | /* Nonzero if it is unsafe to create any new pseudo registers. */ |
191 | int no_new_pseudos; | |
192 | ||
4291d9c8 RS |
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 | ||
4291d9c8 RS |
200 | /* Name to use as base of names for dump output files. */ |
201 | ||
87e11268 | 202 | const char *dump_base_name; |
4291d9c8 | 203 | |
ea67fe71 NS |
204 | /* Name to use as a base for auxiliary output files. */ |
205 | ||
d185d268 | 206 | const char *aux_base_name; |
ea67fe71 | 207 | |
6baf9874 DR |
208 | /* Format to use to print dumpfile index value */ |
209 | #ifndef DUMPFILE_FORMAT | |
210 | #define DUMPFILE_FORMAT ".%02d." | |
211 | #endif | |
212 | ||
4291d9c8 RS |
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 | ||
a27fb29b RS |
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 | ||
a51d908e NB |
224 | /* Debug hooks - dependent upon command line options. */ |
225 | ||
df38ffef | 226 | const struct gcc_debug_hooks *debug_hooks; |
a51d908e | 227 | |
61098249 RH |
228 | /* Describes a dump file. */ |
229 | ||
230 | struct dump_file_info | |
231 | { | |
232 | /* The unique extension to apply, e.g. ".jump". */ | |
854a97f0 | 233 | const char *const extension; |
61098249 RH |
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 | { | |
a194aa56 | 252 | DFI_cgraph, |
61098249 | 253 | DFI_rtl, |
48d9ade5 | 254 | DFI_sibling, |
52a11cbf | 255 | DFI_eh, |
61098249 | 256 | DFI_jump, |
61098249 | 257 | DFI_ssa, |
0b47e4c1 | 258 | DFI_ssa_ccp, |
62d285ff | 259 | DFI_ssa_dce, |
61098249 | 260 | DFI_ussa, |
38c1593d | 261 | DFI_null, |
0826f1d8 JL |
262 | DFI_cse, |
263 | DFI_addressof, | |
61098249 RH |
264 | DFI_gcse, |
265 | DFI_loop, | |
a0134312 | 266 | DFI_bypass, |
51891abe | 267 | DFI_cfg, |
61098249 | 268 | DFI_bp, |
fca9dc00 | 269 | DFI_vpt, |
0fb53e68 | 270 | DFI_ce1, |
5c856b23 | 271 | DFI_tracer, |
617b465c | 272 | DFI_loop2, |
aa888d0f | 273 | DFI_web, |
38c1593d | 274 | DFI_cse2, |
51891abe | 275 | DFI_life, |
61098249 | 276 | DFI_combine, |
0fb53e68 | 277 | DFI_ce2, |
61098249 RH |
278 | DFI_regmove, |
279 | DFI_sched, | |
280 | DFI_lreg, | |
281 | DFI_greg, | |
8bb16620 | 282 | DFI_postreload, |
61098249 RH |
283 | DFI_flow2, |
284 | DFI_peephole2, | |
5fa41e13 | 285 | DFI_rnreg, |
b9422b69 | 286 | DFI_bbro, |
c079e6fe | 287 | DFI_ce3, |
fe3ad572 | 288 | DFI_branch_target_load, |
61098249 | 289 | DFI_sched2, |
1e5fd094 | 290 | DFI_stack, |
61098249 RH |
291 | DFI_mach, |
292 | DFI_dbr, | |
61098249 RH |
293 | DFI_MAX |
294 | }; | |
295 | ||
296 | /* Describes all the dump files. Should be kept in order of the | |
9ec6d7ab RH |
297 | pass and in sync with dump_file_index above. |
298 | ||
299 | Remaining -d letters: | |
300 | ||
fe651b1d | 301 | " m q " |
fca9dc00 | 302 | " JK O Q Y " |
9ec6d7ab | 303 | */ |
61098249 | 304 | |
c083a819 | 305 | static struct dump_file_info dump_file[DFI_MAX] = |
61098249 | 306 | { |
a194aa56 | 307 | { "cgraph", 'U', 0, 0, 0 }, |
61098249 | 308 | { "rtl", 'r', 0, 0, 0 }, |
48d9ade5 | 309 | { "sibling", 'i', 0, 0, 0 }, |
52a11cbf | 310 | { "eh", 'h', 0, 0, 0 }, |
61098249 | 311 | { "jump", 'j', 0, 0, 0 }, |
61098249 | 312 | { "ssa", 'e', 1, 0, 0 }, |
0b47e4c1 | 313 | { "ssaccp", 'W', 1, 0, 0 }, |
62d285ff | 314 | { "ssadce", 'X', 1, 0, 0 }, |
61098249 | 315 | { "ussa", 'e', 1, 0, 0 }, /* Yes, duplicate enable switch. */ |
38c1593d | 316 | { "null", 'u', 0, 0, 0 }, |
0826f1d8 JL |
317 | { "cse", 's', 0, 0, 0 }, |
318 | { "addressof", 'F', 0, 0, 0 }, | |
61098249 RH |
319 | { "gcse", 'G', 1, 0, 0 }, |
320 | { "loop", 'L', 1, 0, 0 }, | |
a0134312 | 321 | { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */ |
51891abe | 322 | { "cfg", 'f', 1, 0, 0 }, |
61098249 | 323 | { "bp", 'b', 1, 0, 0 }, |
fca9dc00 | 324 | { "vpt", 'V', 1, 0, 0 }, |
a9a4005f | 325 | { "ce1", 'C', 1, 0, 0 }, |
5c856b23 | 326 | { "tracer", 'T', 1, 0, 0 }, |
617b465c | 327 | { "loop2", 'L', 1, 0, 0 }, |
aa888d0f | 328 | { "web", 'Z', 0, 0, 0 }, |
38c1593d | 329 | { "cse2", 't', 1, 0, 0 }, |
51891abe | 330 | { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */ |
61098249 | 331 | { "combine", 'c', 1, 0, 0 }, |
0fb53e68 | 332 | { "ce2", 'C', 1, 0, 0 }, |
61098249 RH |
333 | { "regmove", 'N', 1, 0, 0 }, |
334 | { "sched", 'S', 1, 0, 0 }, | |
335 | { "lreg", 'l', 1, 0, 0 }, | |
336 | { "greg", 'g', 1, 0, 0 }, | |
8bb16620 | 337 | { "postreload", 'o', 1, 0, 0 }, |
61098249 RH |
338 | { "flow2", 'w', 1, 0, 0 }, |
339 | { "peephole2", 'z', 1, 0, 0 }, | |
5fa41e13 | 340 | { "rnreg", 'n', 1, 0, 0 }, |
b9422b69 | 341 | { "bbro", 'B', 1, 0, 0 }, |
c079e6fe | 342 | { "ce3", 'E', 1, 0, 0 }, |
fe3ad572 | 343 | { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */ |
61098249 | 344 | { "sched2", 'R', 1, 0, 0 }, |
1e5fd094 | 345 | { "stack", 'k', 1, 0, 0 }, |
61098249 RH |
346 | { "mach", 'M', 1, 0, 0 }, |
347 | { "dbr", 'd', 0, 0, 0 }, | |
61098249 RH |
348 | }; |
349 | ||
e25a75e6 AJ |
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); | |
61098249 RH |
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; | |
735a0e33 | 358 | enum graph_dump_types graph_dump_format; |
4291d9c8 RS |
359 | |
360 | /* Name for output file of assembly code, specified with -o. */ | |
361 | ||
d185d268 | 362 | const char *asm_file_name; |
4291d9c8 | 363 | |
4291d9c8 RS |
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 | ||
c6aded7c | 373 | /* Nonzero means optimize for size. -Os. |
0e9e1e0a KH |
374 | The only valid values are zero and nonzero. When optimize_size is |
375 | nonzero, optimize defaults to 2, but certain individual code | |
c6aded7c AG |
376 | bloating optimizations are disabled. */ |
377 | ||
378 | int optimize_size = 0; | |
379 | ||
00262c8a ML |
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 | ||
881c6935 JM |
388 | /* Nonzero if doing dwarf2 duplicate elimination. */ |
389 | ||
390 | int flag_eliminate_dwarf2_dups = 0; | |
391 | ||
73c68f61 SS |
392 | /* Nonzero if doing unused type elimination. */ |
393 | ||
9552a3e3 | 394 | int flag_eliminate_unused_debug_types = 1; |
73c68f61 | 395 | |
6a08f7b3 DP |
396 | /* Nonzero means emit debugging information only for symbols which are used. */ |
397 | int flag_debug_only_used_symbols = 0; | |
398 | ||
4291d9c8 RS |
399 | /* Nonzero if generating code to do profiling. */ |
400 | ||
401 | int profile_flag = 0; | |
402 | ||
0d332add DE |
403 | /* Nonzero if generating code to profile program flow graph arcs. */ |
404 | ||
405 | int profile_arc_flag = 0; | |
406 | ||
af166e5d ZD |
407 | /* Nonzero if value histograms should be measured. */ |
408 | ||
409 | int flag_profile_values = 0; | |
410 | ||
fca9dc00 ZD |
411 | /* Nonzero if value histograms should be used to optimize code. */ |
412 | int flag_value_profile_transformations = 0; | |
413 | ||
0d332add DE |
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 | ||
854a97f0 | 422 | /* Nonzero if basic blocks should be reordered. */ |
11bdd2ae SC |
423 | |
424 | int flag_reorder_blocks = 0; | |
425 | ||
194734e9 JH |
426 | /* Nonzero if functions should be reordered. */ |
427 | ||
428 | int flag_reorder_functions = 0; | |
429 | ||
854a97f0 | 430 | /* Nonzero if registers should be renamed. */ |
7b82b5da SC |
431 | |
432 | int flag_rename_registers = 0; | |
8582c27b | 433 | int flag_cprop_registers = 0; |
7b82b5da | 434 | |
4291d9c8 RS |
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 | ||
fba0bfd4 | 445 | /* Don't print functions as they are compiled. -quiet. */ |
4291d9c8 RS |
446 | |
447 | int quiet_flag = 0; | |
fba0bfd4 ZW |
448 | |
449 | /* Print times taken by the various passes. -ftime-report. */ | |
450 | ||
6ff3a151 | 451 | int time_report = 0; |
fba0bfd4 ZW |
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 | ||
272d0bee | 458 | /* Nonzero means to collect statistics which might be expensive |
0e5921e8 ZW |
459 | and to print them when we are done. */ |
460 | int flag_detailed_statistics = 0; | |
461 | ||
4ed43216 | 462 | /* A random sequence of characters, unless overridden by user. */ |
c07e5477 NS |
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 | ||
4291d9c8 RS |
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 | ||
958ec8ca JW |
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 | ||
4291d9c8 RS |
499 | /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */ |
500 | ||
958ec8ca | 501 | int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN; |
4291d9c8 RS |
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 | ||
6731a3e3 | 516 | int flag_defer_pop = 0; |
4291d9c8 RS |
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 | ||
8b3686ed RK |
528 | /* Nonzero for -fcse-skip-blocks: |
529 | have cse follow a branch around a block. */ | |
530 | int flag_cse_skip_blocks; | |
531 | ||
4291d9c8 RS |
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 | ||
b17d5d7c | 550 | int flag_old_unroll_loops; |
4291d9c8 RS |
551 | |
552 | /* Nonzero enables loop unrolling in unroll.c. All loops are unrolled. | |
553 | This is generally not a win. */ | |
554 | ||
b17d5d7c ZD |
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. */ | |
4291d9c8 RS |
561 | int flag_unroll_all_loops; |
562 | ||
b17d5d7c ZD |
563 | /* Nonzero enables loop peeling. */ |
564 | int flag_peel_loops; | |
565 | ||
617b465c ZD |
566 | /* Nonzero enables loop unswitching. */ |
567 | int flag_unswitch_loops; | |
568 | ||
0dd0e980 JH |
569 | /* Nonzero enables prefetch optimizations for arrays in loops. */ |
570 | ||
571 | int flag_prefetch_loop_arrays; | |
572 | ||
e5eb27e5 | 573 | /* Nonzero forces all invariant computations in loops to be moved |
854a97f0 | 574 | outside the loop. */ |
e5eb27e5 JL |
575 | |
576 | int flag_move_all_movables = 0; | |
577 | ||
578 | /* Nonzero forces all general induction variables in loops to be | |
854a97f0 | 579 | strength reduced. */ |
e5eb27e5 JL |
580 | |
581 | int flag_reduce_all_givs = 0; | |
582 | ||
9ec36da5 JL |
583 | /* Nonzero to perform full register move optimization passes. This is the |
584 | default for -O2. */ | |
585 | ||
586 | int flag_regmove = 0; | |
587 | ||
4291d9c8 RS |
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 | ||
cf440348 JL |
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 | ||
fd868572 | 609 | /* ... and similar for data. */ |
854a97f0 | 610 | |
fd868572 CM |
611 | int flag_data_sections = 0; |
612 | ||
4291d9c8 RS |
613 | /* Nonzero to inhibit use of define_optimization peephole opts. */ |
614 | ||
615 | int flag_no_peephole = 0; | |
616 | ||
db8cb48e JH |
617 | /* Nonzero allows GCC to optimize sibling and tail recursive calls. */ |
618 | ||
619 | int flag_optimize_sibling_calls = 0; | |
620 | ||
41af162c | 621 | /* Nonzero means the front end generally wants `errno' maintained by math |
de6c5979 | 622 | operations, like built-in SQRT. */ |
41af162c CB |
623 | |
624 | int flag_errno_math = 1; | |
625 | ||
de6c5979 BL |
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 | ||
2e8f2e8f TM |
633 | /* Nonzero means that no NaNs or +-Infs are expected. */ |
634 | ||
635 | int flag_finite_math_only = 0; | |
636 | ||
de6c5979 BL |
637 | /* Zero means that floating-point math operations cannot generate a |
638 | (user-visible) trap. This is the case, for example, in nonstop | |
52bfebf0 | 639 | IEEE 754 arithmetic. Trapping conditions include division by zero, |
26182e15 | 640 | overflow, underflow, invalid and inexact, but does not include |
52bfebf0 | 641 | operations on signaling NaNs (see below). */ |
de6c5979 BL |
642 | |
643 | int flag_trapping_math = 1; | |
644 | ||
039c3d42 RS |
645 | /* Nonzero means disable transformations that assume default floating |
646 | point rounding behavior. */ | |
647 | ||
648 | int flag_rounding_math = 0; | |
649 | ||
52bfebf0 | 650 | /* Nonzero means disable transformations observable by signaling NaNs. |
b20b352b | 651 | This option implies that any operation on an IEEE signaling NaN can |
52bfebf0 RS |
652 | generate a (user-visible) trap. */ |
653 | ||
654 | int flag_signaling_nans = 0; | |
655 | ||
c64f913e CB |
656 | /* 0 means straightforward implementation of complex divide acceptable. |
657 | 1 means wide ranges of inputs must work for complex divide. | |
526aba28 | 658 | 2 means C99-like requirements for complex divide (not yet implemented). */ |
c64f913e CB |
659 | |
660 | int flag_complex_divide_method = 0; | |
661 | ||
4291d9c8 RS |
662 | /* Nonzero means just do syntax checking; don't output anything. */ |
663 | ||
664 | int flag_syntax_only = 0; | |
665 | ||
62551c66 JH |
666 | /* Nonzero means performs web construction pass. */ |
667 | ||
668 | int flag_web; | |
669 | ||
96327cdc JH |
670 | /* Nonzero means perform loop optimizer. */ |
671 | ||
de32c0cb | 672 | int flag_loop_optimize; |
96327cdc JH |
673 | |
674 | /* Nonzero means perform crossjumping. */ | |
675 | ||
de32c0cb | 676 | int flag_crossjumping; |
96327cdc | 677 | |
2c4b77f3 JH |
678 | /* Nonzero means perform if conversion. */ |
679 | ||
de32c0cb | 680 | int flag_if_conversion; |
2c4b77f3 JH |
681 | |
682 | /* Nonzero means perform if conversion after reload. */ | |
683 | ||
de32c0cb | 684 | int flag_if_conversion2; |
2c4b77f3 | 685 | |
b6d24183 JL |
686 | /* Nonzero means to use global dataflow analysis to eliminate |
687 | useless null pointer tests. */ | |
688 | ||
de32c0cb | 689 | int flag_delete_null_pointer_checks; |
b6d24183 | 690 | |
34ee7f82 RS |
691 | /* Nonzero means perform global CSE. */ |
692 | ||
693 | int flag_gcse = 0; | |
694 | ||
a13d4ebf AM |
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 | ||
f5f2e3cd MH |
707 | /* Nonzero if we want to perfrom redundant load after store elimination |
708 | in gcse. */ | |
709 | ||
710 | int flag_gcse_las = 1; | |
711 | ||
fe3ad572 SC |
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 | ||
4291d9c8 RS |
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 | ||
de32c0cb | 725 | int flag_rerun_cse_after_loop; |
4291d9c8 | 726 | |
6d6d0fa0 JL |
727 | /* Nonzero means to run loop optimizations twice. */ |
728 | ||
64fde701 | 729 | int flag_rerun_loop_opt; |
6d6d0fa0 | 730 | |
4291d9c8 RS |
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 | |
ac2a9454 | 737 | go inline everywhere, keep its definition around for debugging |
4291d9c8 RS |
738 | purposes. */ |
739 | ||
740 | int flag_keep_inline_functions; | |
741 | ||
fadb3bc9 | 742 | /* Nonzero means that functions will not be inlined. */ |
4291d9c8 | 743 | |
b0148884 | 744 | int flag_no_inline = 2; |
4291d9c8 | 745 | |
2cb921f4 AH |
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 | ||
b0148884 | 749 | int flag_really_no_inline = 2; |
2cb921f4 | 750 | |
fbe912dd BK |
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 | ||
4291d9c8 RS |
756 | /* Nonzero means we should be saving declaration info into a .X file. */ |
757 | ||
758 | int flag_gen_aux_info = 0; | |
759 | ||
f246a305 RS |
760 | /* Specified name of aux-info file. */ |
761 | ||
d185d268 | 762 | const char *aux_info_file_name; |
f246a305 | 763 | |
4291d9c8 RS |
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. | |
3d78f2e9 RH |
773 | Value is 1 if we are doing "small" pic; value is 2 if we're doing |
774 | "large" pic. */ | |
4291d9c8 RS |
775 | |
776 | int flag_pic; | |
777 | ||
24a4dd31 JJ |
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 | ||
3d78f2e9 RH |
789 | /* Set to the default thread-local storage (tls) model to use. */ |
790 | ||
755ac5d4 | 791 | enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC; |
3d78f2e9 | 792 | |
3d195391 MS |
793 | /* Nonzero means generate extra code for exception handling and enable |
794 | exception handling. */ | |
795 | ||
b53beeb2 | 796 | int flag_exceptions; |
3d195391 | 797 | |
854a97f0 | 798 | /* Nonzero means generate frame unwind info table when supported. */ |
14a774a9 RK |
799 | |
800 | int flag_unwind_tables = 0; | |
801 | ||
f9da5064 KH |
802 | /* Nonzero means generate frame unwind info table exact at each insn |
803 | boundary. */ | |
b932f770 JH |
804 | |
805 | int flag_asynchronous_unwind_tables = 0; | |
806 | ||
2786cbad | 807 | /* Nonzero means don't place uninitialized global data in common storage |
3d195391 | 808 | by default. */ |
4291d9c8 RS |
809 | |
810 | int flag_no_common; | |
811 | ||
4291d9c8 RS |
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 | ||
b9422b69 JH |
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 | ||
8c660648 JL |
832 | /* The following flags have effect only for scheduling before register |
833 | allocation: | |
834 | ||
14b493d6 | 835 | flag_schedule_interblock means schedule insns across basic blocks. |
8c660648 JL |
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 | |
8e7336f8 | 840 | load insns. */ |
8c660648 JL |
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; | |
8c660648 | 846 | |
569fa502 DN |
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 | ||
46d3a873 CC |
861 | int flag_single_precision_constant; |
862 | ||
5527bf14 | 863 | /* flag_branch_on_count_reg means try to replace add-1,compare,branch tupple |
854a97f0 | 864 | by a cheaper branch on a count register. */ |
5527bf14 | 865 | int flag_branch_on_count_reg = 1; |
8c660648 | 866 | |
4291d9c8 | 867 | /* -finhibit-size-directive inhibits output of .size for ELF. |
854a97f0 | 868 | This is used only for compiling crtstuff.c, |
4291d9c8 RS |
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 | ||
9a631e8e RS |
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 | |
3d5cdd42 | 876 | generated assembly code (perhaps while debugging the compiler itself). |
c85f7c16 | 877 | -fno-verbose-asm, the default, causes the extra information |
3d5cdd42 DE |
878 | to be omitted and is useful when comparing two assembler files. */ |
879 | ||
c85f7c16 | 880 | int flag_verbose_asm = 0; |
9a631e8e | 881 | |
3d5cdd42 DE |
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; | |
9a631e8e | 890 | |
c349e40b SC |
891 | /* -dP causes the rtl to be emitted as a comment in assembly. */ |
892 | ||
893 | int flag_dump_rtl_in_asm = 0; | |
894 | ||
4291d9c8 | 895 | /* -fgnu-linker specifies use of the GNU linker for initializations. |
d68c507d RS |
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 | |
4291d9c8 | 901 | int flag_gnu_linker = 1; |
d68c507d | 902 | #endif |
4291d9c8 | 903 | |
27b41650 KG |
904 | /* Nonzero means put zero initialized data in the bss section. */ |
905 | int flag_zero_initialized_in_bss = 1; | |
906 | ||
d9d4fb43 AS |
907 | /* Enable SSA. */ |
908 | int flag_ssa = 0; | |
909 | ||
0b47e4c1 JL |
910 | /* Enable ssa conditional constant propagation. */ |
911 | int flag_ssa_ccp = 0; | |
912 | ||
913 | /* Enable ssa aggressive dead code elimination. */ | |
62d285ff | 914 | int flag_ssa_dce = 0; |
b53978a3 | 915 | |
854a97f0 | 916 | /* Tag all structures with __attribute__(packed). */ |
566cdc73 MM |
917 | int flag_pack_struct = 0; |
918 | ||
bd83d0ac RK |
919 | /* Emit code to check for stack overflow; also may cause large objects |
920 | to be allocated dynamically. */ | |
921 | int flag_stack_check; | |
922 | ||
a157febd GK |
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 | ||
9ae8ffe7 JL |
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 | ||
41472af8 MM |
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 | ||
07417085 KR |
946 | /* Instrument functions with calls at entry and exit, for profiling. */ |
947 | int flag_instrument_function_entry_exit = 0; | |
948 | ||
be163a70 ZW |
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; | |
b8468bc7 | 954 | |
854a97f0 | 955 | /* This will perform a peephole pass before sched2. */ |
ede7cd44 RH |
956 | int flag_peephole2 = 0; |
957 | ||
3ff51205 AH |
958 | /* This will try to guess branch probabilities. */ |
959 | int flag_guess_branch_prob = 0; | |
960 | ||
a8aa7975 | 961 | /* -fcheck-bounds causes gcc to generate array bounds checks. |
e03b7153 | 962 | For C, C++, ObjC: defaults to off. |
a8aa7975 | 963 | For Java: defaults to on. |
e03b7153 | 964 | For Fortran: defaults to off. */ |
a8aa7975 GM |
965 | int flag_bounds_check = 0; |
966 | ||
201556f0 JJ |
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 | ||
673b5311 MM |
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 | ||
ed8d2920 MM |
977 | /* If nonzero, use the graph coloring register allocator. */ |
978 | int flag_new_regalloc = 0; | |
979 | ||
5c856b23 JH |
980 | /* Nonzero if we perform superblock formation. */ |
981 | ||
982 | int flag_tracer = 0; | |
983 | ||
e72fcfe8 JH |
984 | /* Nonzero if we perform whole unit at a time compilation. */ |
985 | ||
986 | int flag_unit_at_a_time = 0; | |
987 | ||
854a97f0 KH |
988 | /* Values of the -falign-* flags: how much to align labels in code. |
989 | 0 means `use default', 1 means `don't align'. | |
efa3896a GK |
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; | |
2cca7283 | 995 | int align_loops_max_skip; |
efa3896a GK |
996 | int align_jumps; |
997 | int align_jumps_log; | |
2cca7283 | 998 | int align_jumps_max_skip; |
efa3896a GK |
999 | int align_labels; |
1000 | int align_labels_log; | |
2cca7283 | 1001 | int align_labels_max_skip; |
efa3896a GK |
1002 | int align_functions; |
1003 | int align_functions_log; | |
1004 | ||
f963b5d9 RS |
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 | ||
b8468bc7 NC |
1009 | typedef struct |
1010 | { | |
c083a819 KG |
1011 | const char *const string; |
1012 | int *const variable; | |
1013 | const int on_value; | |
b8468bc7 NC |
1014 | } |
1015 | lang_independent_options; | |
1016 | ||
4fa26a60 | 1017 | /* Nonzero if signed arithmetic overflow should trap. */ |
91ce572a CC |
1018 | int flag_trapv = 0; |
1019 | ||
4fa26a60 RS |
1020 | /* Nonzero if signed arithmetic overflow should wrap around. */ |
1021 | int flag_wrapv = 0; | |
1022 | ||
c67e6e14 RS |
1023 | /* Nonzero if subexpressions must be evaluated from left-to-right. */ |
1024 | int flag_evaluation_order = 0; | |
1025 | ||
19283265 RH |
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. */ | |
87e11268 | 1030 | const char *user_label_prefix; |
19283265 | 1031 | |
c6d9a88c MM |
1032 | static const param_info lang_independent_params[] = { |
1033 | #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT) \ | |
1c4c47db | 1034 | { OPTION, DEFAULT, HELP }, |
c6d9a88c MM |
1035 | #include "params.def" |
1036 | #undef DEFPARAM | |
1c4c47db | 1037 | { NULL, 0, NULL } |
c6d9a88c MM |
1038 | }; |
1039 | ||
4291d9c8 RS |
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 | ||
c083a819 | 1046 | static const lang_independent_options f_options[] = |
4291d9c8 | 1047 | { |
f3fdaec4 NB |
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 }, | |
62551c66 | 1086 | {"web", &flag_web, 1}, |
f3fdaec4 NB |
1087 | {"gcse", &flag_gcse, 1 }, |
1088 | {"gcse-lm", &flag_gcse_lm, 1 }, | |
1089 | {"gcse-sm", &flag_gcse_sm, 1 }, | |
f5f2e3cd | 1090 | {"gcse-las", &flag_gcse_las, 1 }, |
f3fdaec4 NB |
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 }, | |
569fa502 DN |
1106 | {"sched-stalled-insns", &flag_sched_stalled_insns, 0 }, |
1107 | {"sched-stalled-insns-dep", &flag_sched_stalled_insns_dep, 1 }, | |
f3fdaec4 NB |
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 }, | |
fca9dc00 ZD |
1120 | {"profile-values", &flag_profile_values, 1 }, |
1121 | {"vpt", &flag_value_profile_transformations, 1 }, | |
f3fdaec4 NB |
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 }, | |
039c3d42 | 1162 | {"rounding-math", &flag_rounding_math, 1 }, |
f3fdaec4 NB |
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 } | |
4291d9c8 | 1172 | }; |
b99933c7 | 1173 | |
b8468bc7 NC |
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 | ||
8b60264b | 1180 | static const struct |
b8468bc7 | 1181 | { |
8b60264b KG |
1182 | const char *const name; |
1183 | const int value; | |
1184 | const char *const description; | |
b8468bc7 | 1185 | } |
9cabb1d8 | 1186 | target_switches[] = TARGET_SWITCHES; |
b8468bc7 NC |
1187 | |
1188 | /* This table is similar, but allows the switch to have a value. */ | |
1189 | ||
1190 | #ifdef TARGET_OPTIONS | |
8b60264b | 1191 | static const struct |
b8468bc7 | 1192 | { |
8b60264b KG |
1193 | const char *const prefix; |
1194 | const char **const variable; | |
1195 | const char *const description; | |
c409ea0d | 1196 | const char *const value; |
b8468bc7 | 1197 | } |
9cabb1d8 | 1198 | target_options[] = TARGET_OPTIONS; |
b8468bc7 | 1199 | #endif |
ddc9542b | 1200 | |
4291d9c8 RS |
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 | ||
4291d9c8 RS |
1206 | /* Output files for assembler code (real compiler output) |
1207 | and debugging dumps. */ | |
1208 | ||
1209 | FILE *asm_out_file; | |
1210 | FILE *aux_info_file; | |
032713aa | 1211 | FILE *rtl_dump_file = NULL; |
a194aa56 | 1212 | FILE *cgraph_dump_file = NULL; |
4291d9c8 | 1213 | |
b20d9f0c AO |
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 | ||
0761f342 GDR |
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 | ||
c07e5477 NS |
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 | { | |
c163ddca | 1287 | time_t now = time (NULL); |
c07e5477 NS |
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 | } | |
e61a2eb7 | 1298 | else if (!local_tick) |
c07e5477 NS |
1299 | local_tick = -1; |
1300 | } | |
1301 | ||
1302 | ||
132e01b1 TP |
1303 | /* Decode the string P as an integral parameter. |
1304 | If the string is indeed an integer return its numeric value else | |
192babfd | 1305 | issue an Invalid Option error for the option PNAME and return DEFVAL. |
854a97f0 KH |
1306 | If PNAME is zero just return DEFVAL, do not call error. */ |
1307 | ||
132e01b1 | 1308 | int |
e25a75e6 | 1309 | read_integral_parameter (const char *p, const char *pname, const int defval) |
132e01b1 | 1310 | { |
192babfd | 1311 | const char *endp = p; |
132e01b1 TP |
1312 | |
1313 | while (*endp) | |
1314 | { | |
0df6c2c7 | 1315 | if (ISDIGIT (*endp)) |
132e01b1 TP |
1316 | endp++; |
1317 | else | |
192babfd TP |
1318 | break; |
1319 | } | |
1320 | ||
1321 | if (*endp != 0) | |
1322 | { | |
1323 | if (pname != 0) | |
09e4ab56 | 1324 | error ("invalid option argument `%s'", pname); |
192babfd | 1325 | return defval; |
132e01b1 TP |
1326 | } |
1327 | ||
1328 | return atoi (p); | |
1329 | } | |
4291d9c8 | 1330 | |
4291d9c8 | 1331 | /* Return the logarithm of X, base 2, considering X unsigned, |
37366632 RK |
1332 | if X is a power of 2. Otherwise, returns -1. |
1333 | ||
1334 | This should be used via the `exact_log2' macro. */ | |
4291d9c8 RS |
1335 | |
1336 | int | |
e25a75e6 | 1337 | exact_log2_wide (unsigned HOST_WIDE_INT x) |
4291d9c8 | 1338 | { |
b3694847 | 1339 | int log = 0; |
4291d9c8 RS |
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. | |
37366632 RK |
1349 | If X is 0, return -1. |
1350 | ||
1351 | This should be used via the floor_log2 macro. */ | |
4291d9c8 RS |
1352 | |
1353 | int | |
e25a75e6 | 1354 | floor_log2_wide (unsigned HOST_WIDE_INT x) |
4291d9c8 | 1355 | { |
b3694847 | 1356 | int log = -1; |
4291d9c8 RS |
1357 | while (x != 0) |
1358 | log++, | |
1359 | x >>= 1; | |
1360 | return log; | |
1361 | } | |
1362 | ||
a7023245 | 1363 | /* Handler for fatal signals, such as SIGSEGV. These are transformed |
c770ac2b ZW |
1364 | into ICE messages, which is much more user friendly. In case the |
1365 | error printer crashes, reset the signal to prevent infinite recursion. */ | |
4291d9c8 RS |
1366 | |
1367 | static void | |
e25a75e6 | 1368 | crash_signal (int signo) |
4291d9c8 | 1369 | { |
c770ac2b | 1370 | signal (signo, SIG_DFL); |
9d533cb5 | 1371 | internal_error ("%s", strsignal (signo)); |
4291d9c8 RS |
1372 | } |
1373 | ||
886e0865 GK |
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 | |
e25a75e6 | 1378 | setup_core_dumping (void) |
886e0865 GK |
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) | |
fa6ef813 | 1387 | fatal_error ("getting core file size maximum limit: %m"); |
886e0865 GK |
1388 | rlim.rlim_cur = rlim.rlim_max; |
1389 | if (setrlimit (RLIMIT_CORE, &rlim) != 0) | |
fa6ef813 | 1390 | fatal_error ("setting core file size limit to maximum: %m"); |
886e0865 GK |
1391 | } |
1392 | #endif | |
1393 | diagnostic_abort_on_error (global_dc); | |
1394 | } | |
1395 | ||
1396 | ||
4291d9c8 | 1397 | /* Strip off a legitimate source ending from the input string NAME of |
c62bdc79 | 1398 | length LEN. Rather than having to know the names used by all of |
2290e0ec | 1399 | our front ends, we strip off an ending of a period followed by |
854a97f0 | 1400 | up to five characters. (Java uses ".class".) */ |
4291d9c8 RS |
1401 | |
1402 | void | |
e25a75e6 | 1403 | strip_off_ending (char *name, int len) |
4291d9c8 | 1404 | { |
2290e0ec | 1405 | int i; |
41077ce4 | 1406 | for (i = 2; i < 6 && len > i; i++) |
2290e0ec PB |
1407 | { |
1408 | if (name[len - i] == '.') | |
1409 | { | |
1410 | name[len - i] = '\0'; | |
1411 | break; | |
1412 | } | |
1413 | } | |
4291d9c8 RS |
1414 | } |
1415 | ||
7dce5088 | 1416 | /* Output a quoted string. */ |
0f41302f | 1417 | |
7dce5088 | 1418 | void |
e25a75e6 | 1419 | output_quoted_string (FILE *asm_file, const char *string) |
7dce5088 | 1420 | { |
e9a25f70 JL |
1421 | #ifdef OUTPUT_QUOTED_STRING |
1422 | OUTPUT_QUOTED_STRING (asm_file, string); | |
1423 | #else | |
7dce5088 PE |
1424 | char c; |
1425 | ||
1426 | putc ('\"', asm_file); | |
1427 | while ((c = *string++) != 0) | |
1428 | { | |
042cdf71 ZW |
1429 | if (ISPRINT (c)) |
1430 | { | |
1431 | if (c == '\"' || c == '\\') | |
1432 | putc ('\\', asm_file); | |
1433 | putc (c, asm_file); | |
1434 | } | |
1435 | else | |
211a0cbe | 1436 | fprintf (asm_file, "\\%03o", (unsigned char) c); |
7dce5088 PE |
1437 | } |
1438 | putc ('\"', asm_file); | |
e9a25f70 | 1439 | #endif |
7dce5088 PE |
1440 | } |
1441 | ||
4291d9c8 RS |
1442 | /* Output a file name in the form wanted by System V. */ |
1443 | ||
1444 | void | |
e25a75e6 | 1445 | output_file_directive (FILE *asm_file, const char *input_name) |
4291d9c8 | 1446 | { |
00503146 AH |
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; | |
4291d9c8 RS |
1455 | |
1456 | /* NA gets INPUT_NAME sans directory names. */ | |
1457 | while (na > input_name) | |
1458 | { | |
1a8bb3dd | 1459 | if (IS_DIR_SEPARATOR (na[-1])) |
9cabb1d8 | 1460 | break; |
4291d9c8 RS |
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 | |
7dce5088 PE |
1470 | fprintf (asm_file, "\t.file\t"); |
1471 | output_quoted_string (asm_file, na); | |
1472 | fputc ('\n', asm_file); | |
4291d9c8 RS |
1473 | #endif |
1474 | #endif | |
1475 | } | |
ddc9542b | 1476 | |
61098249 RH |
1477 | /* Routine to open a dump file. Return true if the dump file is enabled. */ |
1478 | ||
1479 | static int | |
e25a75e6 | 1480 | open_dump_file (enum dump_file_index index, tree decl) |
032713aa | 1481 | { |
61098249 RH |
1482 | char *dump_name; |
1483 | const char *open_arg; | |
1484 | char seq[16]; | |
1485 | ||
1486 | if (! dump_file[index].enabled) | |
1487 | return 0; | |
0f41302f | 1488 | |
2a9a326b AS |
1489 | timevar_push (TV_DUMP); |
1490 | if (rtl_dump_file != NULL) | |
1491 | fclose (rtl_dump_file); | |
854a97f0 | 1492 | |
6baf9874 | 1493 | sprintf (seq, DUMPFILE_FORMAT, index); |
61098249 | 1494 | |
2a9a326b AS |
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"; | |
61098249 | 1510 | |
2a9a326b AS |
1511 | dump_name = concat (dump_base_name, seq, |
1512 | dump_file[index].extension, NULL); | |
61098249 | 1513 | |
2a9a326b AS |
1514 | rtl_dump_file = fopen (dump_name, open_arg); |
1515 | if (rtl_dump_file == NULL) | |
fa6ef813 | 1516 | fatal_error ("can't open %s: %m", dump_name); |
854a97f0 | 1517 | |
2a9a326b | 1518 | free (dump_name); |
032713aa | 1519 | |
2a9a326b | 1520 | if (decl) |
0f72964f JH |
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 | : ""); | |
2a9a326b AS |
1528 | |
1529 | timevar_pop (TV_DUMP); | |
61098249 | 1530 | return 1; |
032713aa NC |
1531 | } |
1532 | ||
1533 | /* Routine to close a dump file. */ | |
61098249 | 1534 | |
032713aa | 1535 | static void |
e25a75e6 AJ |
1536 | close_dump_file (enum dump_file_index index, |
1537 | void (*func) (FILE *, rtx), | |
1538 | rtx insns) | |
032713aa | 1539 | { |
61098249 RH |
1540 | if (! rtl_dump_file) |
1541 | return; | |
1542 | ||
2a9a326b AS |
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; | |
61098249 | 1550 | |
6baf9874 | 1551 | sprintf (seq, DUMPFILE_FORMAT, index); |
2a9a326b AS |
1552 | suffix = concat (seq, dump_file[index].extension, NULL); |
1553 | print_rtl_graph_with_bb (dump_base_name, suffix, insns); | |
1554 | free (suffix); | |
1555 | } | |
61098249 | 1556 | |
2a9a326b AS |
1557 | if (func && insns) |
1558 | func (rtl_dump_file, insns); | |
854a97f0 | 1559 | |
2a9a326b AS |
1560 | fflush (rtl_dump_file); |
1561 | fclose (rtl_dump_file); | |
854a97f0 | 1562 | |
2a9a326b AS |
1563 | rtl_dump_file = NULL; |
1564 | timevar_pop (TV_DUMP); | |
dfe1a916 DE |
1565 | } |
1566 | ||
32291f94 MM |
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. | |
0e9e1e0a | 1570 | Returns nonzero if anything was put out. */ |
854a97f0 | 1571 | |
32291f94 | 1572 | int |
e25a75e6 | 1573 | wrapup_global_declarations (tree *vec, int len) |
32291f94 MM |
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]; | |
854a97f0 | 1583 | |
2b59501b | 1584 | /* We're not deferring this any longer. Assignment is |
3dc575ff | 1585 | conditional to avoid needlessly dirtying PCH pages. */ |
2b59501b MA |
1586 | if (DECL_DEFER_OUTPUT (decl) != 0) |
1587 | DECL_DEFER_OUTPUT (decl) = 0; | |
854a97f0 | 1588 | |
48a7a235 NB |
1589 | if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0) |
1590 | (*lang_hooks.finish_incomplete_decl) (decl); | |
32291f94 MM |
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 | ||
5cc90635 | 1631 | if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl)) |
32291f94 | 1632 | { |
5cc90635 JM |
1633 | bool needed = 1; |
1634 | ||
e69529cd JH |
1635 | if (flag_unit_at_a_time |
1636 | && cgraph_varpool_node (decl)->finalized) | |
1637 | needed = 0; | |
b379a593 | 1638 | else if ((flag_unit_at_a_time && !cgraph_global_info_ready) |
e69529cd JH |
1639 | && (TREE_USED (decl) |
1640 | || TREE_USED (DECL_ASSEMBLER_NAME (decl)))) | |
1641 | /* needed */; | |
1642 | else if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))) | |
5cc90635 JM |
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 | } | |
32291f94 MM |
1656 | } |
1657 | ||
1658 | if (TREE_CODE (decl) == FUNCTION_DECL | |
1659 | && DECL_INITIAL (decl) != 0 | |
1660 | && DECL_SAVED_INSNS (decl) != 0 | |
d560a41c | 1661 | && DECL_SAVED_INSNS (decl)->saved_for_inline |
32291f94 | 1662 | && (flag_keep_inline_functions |
59182242 | 1663 | || (TREE_PUBLIC (decl) && !DECL_COMDAT (decl)) |
32291f94 MM |
1664 | || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))) |
1665 | { | |
1666 | reconsider = 1; | |
32291f94 | 1667 | output_inline_function (decl); |
32291f94 MM |
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. */ | |
854a97f0 | 1681 | |
32291f94 | 1682 | void |
e25a75e6 | 1683 | check_global_declarations (tree *vec, int len) |
32291f94 MM |
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. */ | |
19e7881c | 1697 | SET_DECL_RTL (decl, NULL_RTX); |
32291f94 MM |
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 | |
078721e1 | 1705 | && (warn_unused_function |
32291f94 MM |
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))) | |
ddd2d57e | 1713 | pedwarn ("%J'%F' used but never defined", decl, decl); |
32291f94 | 1714 | else |
ddd2d57e | 1715 | warning ("%J'%F' declared `static' but never defined", decl, decl); |
32291f94 MM |
1716 | /* This symbol is effectively an "extern" declaration now. */ |
1717 | TREE_PUBLIC (decl) = 1; | |
1718 | assemble_external (decl); | |
1719 | } | |
1720 | ||
ef4f94ac RH |
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)) | |
32291f94 MM |
1728 | && ! DECL_EXTERNAL (decl) |
1729 | && ! TREE_PUBLIC (decl) | |
36b29d7d GK |
1730 | /* A volatile variable might be used in some non-obvious way. */ |
1731 | && ! TREE_THIS_VOLATILE (decl) | |
ef4f94ac RH |
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)) | |
ddd2d57e | 1736 | warning ("%J'%D' defined but not used", decl, decl); |
32291f94 | 1737 | |
33c21f5c HPN |
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 | } | |
32291f94 MM |
1746 | } |
1747 | } | |
032713aa | 1748 | |
43f9ce02 GDR |
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)), | |
f31686a3 | 1759 | DECL_SOURCE_FILE (node), DECL_SOURCE_LINE (node)); |
43f9ce02 GDR |
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, | |
f31686a3 | 1775 | DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); |
43f9ce02 GDR |
1776 | else |
1777 | warning ("`%s' is deprecated", what); | |
1778 | } | |
1779 | else if (decl) | |
1780 | warning ("type is deprecated (declared at %s:%d)", | |
f31686a3 | 1781 | DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); |
43f9ce02 GDR |
1782 | else |
1783 | warning ("type is deprecated"); | |
1784 | } | |
1785 | } | |
1786 | ||
070588f0 | 1787 | /* Save the current INPUT_LOCATION on the top entry in the |
68723fae | 1788 | INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the |
070588f0 | 1789 | INPUT_LOCATION accordingly. */ |
68723fae MM |
1790 | |
1791 | void | |
e25a75e6 | 1792 | push_srcloc (const char *file, int line) |
68723fae MM |
1793 | { |
1794 | struct file_stack *fs; | |
1795 | ||
703ad42b | 1796 | fs = xmalloc (sizeof (struct file_stack)); |
6060edcb | 1797 | fs->location = input_location; |
68723fae | 1798 | fs->next = input_file_stack; |
640da953 PB |
1799 | input_filename = file; |
1800 | input_line = line; | |
68723fae MM |
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. | |
070588f0 NS |
1806 | Restore the INPUT_LOCATION from the new topmost entry on the |
1807 | stack. */ | |
68723fae MM |
1808 | |
1809 | void | |
e25a75e6 | 1810 | pop_srcloc (void) |
68723fae MM |
1811 | { |
1812 | struct file_stack *fs; | |
854a97f0 | 1813 | |
68723fae | 1814 | fs = input_file_stack; |
640da953 | 1815 | input_location = fs->location; |
68723fae MM |
1816 | input_file_stack = fs->next; |
1817 | free (fs); | |
1818 | input_file_stack_tick++; | |
68723fae MM |
1819 | } |
1820 | ||
f5e99456 NB |
1821 | /* Compile an entire translation unit. Write a file of assembly |
1822 | output and various debugging dumps. */ | |
4291d9c8 RS |
1823 | |
1824 | static void | |
e25a75e6 | 1825 | compile_file (void) |
4291d9c8 | 1826 | { |
4291d9c8 RS |
1827 | /* Initialize yet another pass. */ |
1828 | ||
b93a436e | 1829 | init_final (main_input_filename); |
ca29da43 | 1830 | coverage_init (aux_base_name); |
4291d9c8 | 1831 | |
2a9a326b | 1832 | timevar_push (TV_PARSE); |
4291d9c8 | 1833 | |
52dabb6c NB |
1834 | /* Call the parser, which parses the entire file (calling |
1835 | rest_of_compilation for each function). */ | |
ff45c01e | 1836 | (*lang_hooks.parse_file) (set_yydebug); |
4291d9c8 | 1837 | |
7cb4ff28 ZW |
1838 | /* In case there were missing block closers, |
1839 | get us back to the global binding level. */ | |
37207ee7 | 1840 | (*lang_hooks.clear_binding_stack) (); |
4291d9c8 RS |
1841 | |
1842 | /* Compilation is now finished except for writing | |
1843 | what's left of the symbol table output. */ | |
2a9a326b | 1844 | timevar_pop (TV_PARSE); |
4291d9c8 | 1845 | |
1fe65c00 | 1846 | if (flag_syntax_only) |
22703ccc | 1847 | return; |
1fe65c00 | 1848 | |
2b59501b | 1849 | (*lang_hooks.decls.final_write_globals)(); |
4291d9c8 | 1850 | |
e69529cd JH |
1851 | cgraph_varpool_assemble_pending_decls (); |
1852 | ||
ca29da43 NS |
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 (); | |
2668793e | 1857 | |
4b8af8d9 JM |
1858 | /* Write out any pending weak symbol declarations. */ |
1859 | ||
1860 | weak_finish (); | |
1861 | ||
854a97f0 | 1862 | /* Do dbx symbols. */ |
2a9a326b | 1863 | timevar_push (TV_SYMOUT); |
7f905405 | 1864 | |
0021b564 JM |
1865 | #ifdef DWARF2_UNWIND_INFO |
1866 | if (dwarf2out_do_frame ()) | |
1867 | dwarf2out_frame_finish (); | |
1868 | #endif | |
1869 | ||
e2a12aca | 1870 | (*debug_hooks->finish) (main_input_filename); |
2a9a326b | 1871 | timevar_pop (TV_SYMOUT); |
9a666dda | 1872 | |
4291d9c8 RS |
1873 | /* Output some stuff at end of file if nec. */ |
1874 | ||
2a1ee410 RH |
1875 | dw2_output_indirect_constants (); |
1876 | ||
51891abe | 1877 | if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities) |
61098249 | 1878 | { |
2a9a326b | 1879 | timevar_push (TV_DUMP); |
61098249 | 1880 | open_dump_file (DFI_bp, NULL); |
51891abe JH |
1881 | |
1882 | end_branch_prob (); | |
1883 | ||
61098249 | 1884 | close_dump_file (DFI_bp, NULL, NULL_RTX); |
2a9a326b | 1885 | timevar_pop (TV_DUMP); |
61098249 | 1886 | } |
854a97f0 | 1887 | |
a5fe455b | 1888 | targetm.asm_out.file_end (); |
4291d9c8 | 1889 | |
acb0db7b ZW |
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 | ||
61098249 | 1899 | if (optimize > 0 && open_dump_file (DFI_combine, NULL)) |
4291d9c8 | 1900 | { |
2a9a326b AS |
1901 | timevar_push (TV_DUMP); |
1902 | dump_combine_total_stats (rtl_dump_file); | |
61098249 | 1903 | close_dump_file (DFI_combine, NULL, NULL_RTX); |
2a9a326b | 1904 | timevar_pop (TV_DUMP); |
4291d9c8 | 1905 | } |
4291d9c8 | 1906 | } |
ddc9542b | 1907 | |
4291d9c8 RS |
1908 | /* This is called from various places for FUNCTION_DECL, VAR_DECL, |
1909 | and TYPE_DECL nodes. | |
1910 | ||
ef6748cb MM |
1911 | This does nothing for local (non-static) variables, unless the |
1912 | variable is a register variable with an ASMSPEC. In that case, or | |
d558416e | 1913 | if the variable is not an automatic, it sets up the RTL and |
ef6748cb MM |
1914 | outputs any assembler code (label definition, storage allocation |
1915 | and initialization). | |
4291d9c8 RS |
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 | |
e25a75e6 AJ |
1922 | rest_of_decl_compilation (tree decl, |
1923 | const char *asmspec, | |
1924 | int top_level, | |
1925 | int at_end) | |
4291d9c8 | 1926 | { |
b14707c3 RH |
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)); | |
9cabb1d8 | 1936 | assemble_alias (decl, alias); |
b14707c3 RH |
1937 | } |
1938 | } | |
1939 | ||
4291d9c8 RS |
1940 | /* Forward declarations for nested functions are not "external", |
1941 | but we need to treat them as if they were. */ | |
216d5cdd | 1942 | if (TREE_STATIC (decl) || DECL_EXTERNAL (decl) |
4291d9c8 | 1943 | || TREE_CODE (decl) == FUNCTION_DECL) |
2a9a326b AS |
1944 | { |
1945 | timevar_push (TV_VARCONST); | |
b14707c3 | 1946 | |
8ce0a8a5 | 1947 | if (asmspec) |
9cabb1d8 | 1948 | make_decl_rtl (decl, asmspec); |
b14707c3 RH |
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. */ | |
7e668417 | 1952 | if ((at_end || !DECL_DEFER_OUTPUT (decl)) && !DECL_EXTERNAL (decl)) |
e69529cd | 1953 | { |
5c20c06c JH |
1954 | if (flag_unit_at_a_time && !cgraph_global_info_ready |
1955 | && TREE_CODE (decl) != FUNCTION_DECL && top_level) | |
e69529cd JH |
1956 | cgraph_varpool_finalize_decl (decl); |
1957 | else | |
1958 | assemble_variable (decl, top_level, at_end, 0); | |
1959 | } | |
35d8c8e2 SB |
1960 | |
1961 | #ifdef ASM_FINISH_DECLARE_OBJECT | |
2a9a326b AS |
1962 | if (decl == last_assemble_variable_decl) |
1963 | { | |
1964 | ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl, | |
1965 | top_level, at_end); | |
1966 | } | |
35d8c8e2 | 1967 | #endif |
b14707c3 | 1968 | |
2a9a326b AS |
1969 | timevar_pop (TV_VARCONST); |
1970 | } | |
216d5cdd | 1971 | else if (DECL_REGISTER (decl) && asmspec != 0) |
4291d9c8 RS |
1972 | { |
1973 | if (decode_reg_name (asmspec) >= 0) | |
1974 | { | |
19e7881c | 1975 | SET_DECL_RTL (decl, NULL_RTX); |
6c418184 | 1976 | make_decl_rtl (decl, asmspec); |
4291d9c8 RS |
1977 | } |
1978 | else | |
8f17b5c5 MM |
1979 | { |
1980 | error ("invalid register name `%s' for register variable", asmspec); | |
1981 | DECL_REGISTER (decl) = 0; | |
19e7881c MM |
1982 | if (!top_level) |
1983 | expand_decl (decl); | |
8f17b5c5 | 1984 | } |
4291d9c8 | 1985 | } |
f246a305 RS |
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) | |
2a9a326b AS |
1989 | { |
1990 | timevar_push (TV_SYMOUT); | |
1991 | dbxout_symbol (decl, 0); | |
1992 | timevar_pop (TV_SYMOUT); | |
1993 | } | |
4291d9c8 RS |
1994 | #endif |
1995 | #ifdef SDB_DEBUGGING_INFO | |
1996 | else if (write_symbols == SDB_DEBUG && top_level | |
1997 | && TREE_CODE (decl) == TYPE_DECL) | |
2a9a326b AS |
1998 | { |
1999 | timevar_push (TV_SYMOUT); | |
2000 | sdbout_symbol (decl, 0); | |
2001 | timevar_pop (TV_SYMOUT); | |
2002 | } | |
4291d9c8 | 2003 | #endif |
cc0017a9 ZD |
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 | |
4291d9c8 RS |
2015 | } |
2016 | ||
2017 | /* Called after finishing a record, union or enumeral type. */ | |
2018 | ||
2019 | void | |
e25a75e6 | 2020 | rest_of_type_compilation ( |
35d8c8e2 SB |
2021 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) \ |
2022 | || defined (SDB_DEBUGGING_INFO) || defined (DWARF2_DEBUGGING_INFO) | |
e25a75e6 AJ |
2023 | tree type, |
2024 | int toplev | |
114791ea | 2025 | #else |
e25a75e6 | 2026 | tree type ATTRIBUTE_UNUSED, |
05a0e2af | 2027 | int toplev ATTRIBUTE_UNUSED |
114791ea | 2028 | #endif |
e25a75e6 | 2029 | ) |
4291d9c8 | 2030 | { |
33c21f5c HPN |
2031 | /* Avoid confusing the debug information machinery when there are |
2032 | errors. */ | |
2033 | if (errorcount != 0 || sorrycount != 0) | |
2034 | return; | |
2035 | ||
2a9a326b | 2036 | timevar_push (TV_SYMOUT); |
f246a305 RS |
2037 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
2038 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) | |
2a9a326b | 2039 | dbxout_symbol (TYPE_STUB_DECL (type), !toplev); |
4291d9c8 RS |
2040 | #endif |
2041 | #ifdef SDB_DEBUGGING_INFO | |
2042 | if (write_symbols == SDB_DEBUG) | |
d8d1d62b | 2043 | sdbout_symbol (TYPE_STUB_DECL (type), !toplev); |
881c6935 JM |
2044 | #endif |
2045 | #ifdef DWARF2_DEBUGGING_INFO | |
7a0c8d71 DR |
2046 | if ((write_symbols == DWARF2_DEBUG |
2047 | || write_symbols == VMS_AND_DWARF2_DEBUG) | |
2048 | && toplev) | |
881c6935 | 2049 | dwarf2out_decl (TYPE_STUB_DECL (type)); |
4291d9c8 | 2050 | #endif |
2a9a326b | 2051 | timevar_pop (TV_SYMOUT); |
4291d9c8 RS |
2052 | } |
2053 | ||
ddc9542b AH |
2054 | /* Turn the RTL into assembly. */ |
2055 | static void | |
2056 | rest_of_handle_final (tree decl, rtx insns) | |
4291d9c8 | 2057 | { |
ddc9542b AH |
2058 | timevar_push (TV_FINAL); |
2059 | { | |
2060 | rtx x; | |
2061 | const char *fnname; | |
4291d9c8 | 2062 | |
ddc9542b AH |
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. */ | |
2a9a326b | 2065 | |
ddc9542b AH |
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); | |
1b3d8f8a | 2073 | |
ddc9542b AH |
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 (); | |
d511f9d5 | 2078 | |
ddc9542b AH |
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 | |
fcd7f76b | 2084 | |
ddc9542b | 2085 | assemble_end_function (decl, fnname); |
e619323d | 2086 | |
ddc9542b AH |
2087 | #ifndef IA64_UNWIND_INFO |
2088 | /* Otherwise, it feels unclean to switch sections in the middle. */ | |
2089 | output_function_exception_table (); | |
2090 | #endif | |
1f8f4a0b | 2091 | |
ddc9542b AH |
2092 | if (! quiet_flag) |
2093 | fflush (asm_out_file); | |
4291d9c8 | 2094 | |
ddc9542b AH |
2095 | /* Release all memory allocated by flow. */ |
2096 | free_basic_block_vars (0); | |
14a774a9 | 2097 | |
ddc9542b AH |
2098 | /* Release all memory held by regsets now. */ |
2099 | regset_release_memory (); | |
2100 | } | |
2101 | timevar_pop (TV_FINAL); | |
4291d9c8 | 2102 | |
ddc9542b AH |
2103 | ggc_collect (); |
2104 | } | |
4291d9c8 | 2105 | |
ddc9542b AH |
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); | |
4291d9c8 | 2113 | |
ddc9542b | 2114 | dbr_schedule (insns, rtl_dump_file); |
4291d9c8 | 2115 | |
ddc9542b AH |
2116 | close_dump_file (DFI_dbr, print_rtl, insns); |
2117 | timevar_pop (TV_DBR_SCHED); | |
f93dacbd | 2118 | |
ddc9542b AH |
2119 | ggc_collect (); |
2120 | } | |
2121 | #endif | |
3c030e88 | 2122 | |
ddc9542b AH |
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 | { | |
7f14bbe6 JJ |
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 | ||
ddc9542b AH |
2146 | timevar_push (TV_REG_STACK); |
2147 | open_dump_file (DFI_stack, decl); | |
a701efba | 2148 | |
ddc9542b AH |
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); | |
4291d9c8 | 2157 | } |
b8471b65 | 2158 | } |
07af9d16 | 2159 | |
ddc9542b AH |
2160 | close_dump_file (DFI_stack, print_rtl_with_bb, insns); |
2161 | timevar_pop (TV_REG_STACK); | |
c28abdf0 | 2162 | |
1f8f4a0b | 2163 | ggc_collect (); |
ddc9542b AH |
2164 | } |
2165 | #endif | |
0a1c58a2 | 2166 | |
49ad7cfa | 2167 | |
ddc9542b AH |
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); | |
4291d9c8 | 2174 | |
ddc9542b | 2175 | (*targetm.machine_dependent_reorg) (); |
21c7361e | 2176 | |
ddc9542b AH |
2177 | close_dump_file (DFI_mach, print_rtl, insns); |
2178 | timevar_pop (TV_MACH_DEP); | |
4291d9c8 | 2179 | |
ddc9542b AH |
2180 | ggc_collect (); |
2181 | } | |
d92b4486 | 2182 | |
969d70ca | 2183 | |
ddc9542b AH |
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; | |
ac228d4e | 2190 | |
ddc9542b AH |
2191 | delete_trivially_dead_insns (insns, max_reg_num ()); |
2192 | reg_alloc (); | |
969d70ca | 2193 | |
ddc9542b AH |
2194 | timevar_pop (TV_LOCAL_ALLOC); |
2195 | if (dump_file[DFI_lreg].enabled) | |
9d9e5c09 | 2196 | { |
ddc9542b | 2197 | timevar_push (TV_DUMP); |
9d9e5c09 | 2198 | |
ddc9542b AH |
2199 | close_dump_file (DFI_lreg, NULL, NULL); |
2200 | timevar_pop (TV_DUMP); | |
2201 | } | |
5204d665 | 2202 | |
ddc9542b AH |
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); | |
d92b4486 | 2206 | |
ddc9542b AH |
2207 | build_insn_chain (insns); |
2208 | failure = reload (insns, 0); | |
2a9a326b | 2209 | |
ddc9542b AH |
2210 | timevar_pop (TV_GLOBAL_ALLOC); |
2211 | ||
2212 | if (dump_file[DFI_greg].enabled) | |
52a11cbf | 2213 | { |
ddc9542b | 2214 | timevar_push (TV_DUMP); |
52a11cbf | 2215 | |
ddc9542b | 2216 | dump_global_regs (rtl_dump_file); |
52a11cbf | 2217 | |
ddc9542b AH |
2218 | close_dump_file (DFI_greg, print_rtl_with_bb, insns); |
2219 | timevar_pop (TV_DUMP); | |
52a11cbf RH |
2220 | } |
2221 | ||
ddc9542b AH |
2222 | if (failure) |
2223 | return true; | |
4291d9c8 | 2224 | |
ddc9542b AH |
2225 | reload_completed = 1; |
2226 | *rebuild_notes = 0; | |
4291d9c8 | 2227 | |
ddc9542b AH |
2228 | return false; |
2229 | } | |
4291d9c8 | 2230 | |
ddc9542b AH |
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; | |
c9ec4f99 | 2237 | |
ddc9542b AH |
2238 | /* Allocate the reg_renumber array. */ |
2239 | allocate_reg_info (max_regno, FALSE, TRUE); | |
4291d9c8 | 2240 | |
ddc9542b | 2241 | /* And the reg_equiv_memory_loc array. */ |
703ad42b | 2242 | reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx)); |
02db399d | 2243 | |
ddc9542b | 2244 | allocate_initial_values (reg_equiv_memory_loc); |
994a57cd | 2245 | |
ddc9542b AH |
2246 | regclass (insns, max_reg_num (), rtl_dump_file); |
2247 | *rebuild_notes = local_alloc (); | |
2a9a326b | 2248 | |
ddc9542b | 2249 | timevar_pop (TV_LOCAL_ALLOC); |
3c030e88 | 2250 | |
ddc9542b | 2251 | if (dump_file[DFI_lreg].enabled) |
1c4a429a | 2252 | { |
ddc9542b AH |
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); | |
1c4a429a | 2260 | } |
2a9a326b | 2261 | |
ddc9542b | 2262 | ggc_collect (); |
673b5311 | 2263 | |
ddc9542b AH |
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 | |
a18820c6 | 2273 | { |
ddc9542b AH |
2274 | build_insn_chain (insns); |
2275 | failure = reload (insns, 0); | |
a18820c6 RH |
2276 | } |
2277 | ||
ddc9542b | 2278 | timevar_pop (TV_GLOBAL_ALLOC); |
0826f1d8 | 2279 | |
ddc9542b AH |
2280 | if (dump_file[DFI_greg].enabled) |
2281 | { | |
2282 | timevar_push (TV_DUMP); | |
0826f1d8 | 2283 | |
ddc9542b | 2284 | dump_global_regs (rtl_dump_file); |
0826f1d8 | 2285 | |
ddc9542b AH |
2286 | close_dump_file (DFI_greg, print_rtl_with_bb, insns); |
2287 | timevar_pop (TV_DUMP); | |
2288 | } | |
0826f1d8 | 2289 | |
ddc9542b AH |
2290 | return failure; |
2291 | } | |
0b47e4c1 | 2292 | |
ddc9542b AH |
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); | |
0b47e4c1 | 2299 | |
ddc9542b AH |
2300 | if (flag_rename_registers) |
2301 | regrename_optimize (); | |
2302 | if (flag_cprop_registers) | |
2303 | copyprop_hardreg_forward (); | |
0b47e4c1 | 2304 | |
ddc9542b AH |
2305 | close_dump_file (DFI_rnreg, print_rtl_with_bb, insns); |
2306 | timevar_pop (TV_RENAME_REGISTERS); | |
2307 | } | |
0b47e4c1 | 2308 | |
ddc9542b AH |
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); | |
e25a75e6 | 2331 | } |
ddc9542b | 2332 | |
a2f8629a | 2333 | #ifdef INSN_SCHEDULING |
ddc9542b AH |
2334 | /* Run instruction scheduler. */ |
2335 | static void | |
2336 | rest_of_handle_sched (tree decl, rtx insns) | |
2337 | { | |
2338 | timevar_push (TV_SCHED); | |
0826f1d8 | 2339 | |
ddc9542b AH |
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); | |
0826f1d8 | 2345 | |
ddc9542b AH |
2346 | /* Do control and data sched analysis, |
2347 | and write some of the results to dump file. */ | |
0826f1d8 | 2348 | |
ddc9542b | 2349 | schedule_insns (rtl_dump_file); |
0826f1d8 | 2350 | |
ddc9542b AH |
2351 | close_dump_file (DFI_sched, print_rtl_with_bb, insns); |
2352 | } | |
ddc9542b | 2353 | timevar_pop (TV_SCHED); |
0826f1d8 | 2354 | |
ddc9542b AH |
2355 | ggc_collect (); |
2356 | } | |
0826f1d8 | 2357 | |
ddc9542b AH |
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); | |
0826f1d8 | 2364 | |
ddc9542b AH |
2365 | /* Do control and data sched analysis again, |
2366 | and write some more of the results to dump file. */ | |
0826f1d8 | 2367 | |
ddc9542b | 2368 | split_all_insns (1); |
0826f1d8 | 2369 | |
ddc9542b AH |
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); | |
0826f1d8 | 2377 | } |
ddc9542b AH |
2378 | else |
2379 | schedule_insns (rtl_dump_file); | |
0826f1d8 | 2380 | |
ddc9542b AH |
2381 | close_dump_file (DFI_sched2, print_rtl_with_bb, insns); |
2382 | timevar_pop (TV_SCHED2); | |
9ec6d7ab | 2383 | |
ddc9542b AH |
2384 | ggc_collect (); |
2385 | } | |
2386 | #endif | |
38c1593d | 2387 | |
ddc9542b AH |
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); | |
2a9a326b | 2395 | |
ddc9542b | 2396 | regmove_optimize (insns, max_reg_num (), rtl_dump_file); |
a18820c6 | 2397 | |
ddc9542b AH |
2398 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE); |
2399 | close_dump_file (DFI_regmove, print_rtl_with_bb, insns); | |
2400 | timevar_pop (TV_REGMOVE); | |
dfdb644f | 2401 | |
1f8f4a0b | 2402 | ggc_collect (); |
ddc9542b | 2403 | } |
a3770a81 | 2404 | |
ddc9542b AH |
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 | } | |
4291d9c8 | 2419 | |
ddc9542b AH |
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) | |
4291d9c8 | 2426 | { |
ddc9542b | 2427 | timevar_push (TV_IFCVT); |
38c1593d JH |
2428 | if (rtl_dump_file) |
2429 | dump_flow_info (rtl_dump_file); | |
ddc9542b AH |
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 | } | |
032713aa | 2441 | |
ddc9542b AH |
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); | |
4291d9c8 | 2449 | |
ddc9542b AH |
2450 | no_new_pseudos = 0; |
2451 | if_convert (1); | |
2452 | no_new_pseudos = 1; | |
a18820c6 | 2453 | |
ddc9542b AH |
2454 | close_dump_file (DFI_ce2, print_rtl_with_bb, insns); |
2455 | timevar_pop (TV_IFCVT); | |
2456 | } | |
2ca6672b | 2457 | |
62551c66 JH |
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 | ||
ddc9542b AH |
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; | |
c5c76735 | 2477 | |
ddc9542b AH |
2478 | timevar_push (TV_BRANCH_PROB); |
2479 | open_dump_file (DFI_bp, decl); | |
fca9dc00 | 2480 | |
ddc9542b AH |
2481 | if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities) |
2482 | branch_prob (); | |
2a9a326b | 2483 | |
ddc9542b AH |
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); | |
4291d9c8 | 2490 | |
ddc9542b AH |
2491 | /* Estimate using heuristics if no profiling info is available. */ |
2492 | if (flag_guess_branch_prob) | |
2493 | estimate_probability (&loops); | |
735a0e33 | 2494 | |
ddc9542b AH |
2495 | flow_loops_free (&loops); |
2496 | close_dump_file (DFI_bp, print_rtl_with_bb, insns); | |
2497 | timevar_pop (TV_BRANCH_PROB); | |
2498 | } | |
2499 | ||
fca9dc00 ZD |
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 | ||
ddc9542b AH |
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 (); | |
4291d9c8 | 2535 | |
ddc9542b AH |
2536 | close_dump_file (DFI_cfg, print_rtl_with_bb, insns); |
2537 | } | |
2538 | ||
2539 | /* Purge addressofs. */ | |
2540 | static void | |
f129791c | 2541 | rest_of_handle_addressof (tree decl, rtx insns) |
ddc9542b | 2542 | { |
61098249 RH |
2543 | open_dump_file (DFI_addressof, decl); |
2544 | ||
e9a25f70 | 2545 | purge_addressof (insns); |
f129791c EB |
2546 | if (optimize && purge_all_dead_edges (0)) |
2547 | delete_unreachable_blocks (); | |
e9a25f70 JL |
2548 | reg_scan (insns, max_reg_num (), 1); |
2549 | ||
61098249 | 2550 | close_dump_file (DFI_addressof, print_rtl, insns); |
ddc9542b | 2551 | } |
735a0e33 | 2552 | |
ddc9542b AH |
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); | |
a3770a81 | 2566 | |
ddc9542b AH |
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. | |
7506f491 | 2570 | |
ddc9542b AH |
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); | |
48aba75b | 2587 | |
ddc9542b | 2588 | cleanup_cfg (CLEANUP_EXPENSIVE); |
735a0e33 | 2589 | |
ddc9542b AH |
2590 | if (bypass_jumps (rtl_dump_file)) |
2591 | { | |
b90e45ae | 2592 | rebuild_jump_labels (insns); |
ddc9542b | 2593 | cleanup_cfg (CLEANUP_EXPENSIVE); |
2ca6672b | 2594 | delete_trivially_dead_insns (insns, max_reg_num ()); |
ddc9542b | 2595 | } |
e78d9500 | 2596 | |
ddc9542b AH |
2597 | close_dump_file (DFI_bypass, print_rtl_with_bb, insns); |
2598 | timevar_pop (TV_BYPASS); | |
791f5e8d | 2599 | |
ddc9542b | 2600 | ggc_collect (); |
3d1f4922 | 2601 | |
ddc9542b AH |
2602 | #ifdef ENABLE_CHECKING |
2603 | verify_flow_info (); | |
2604 | #endif | |
2605 | } | |
5262d6b6 | 2606 | |
ddc9542b AH |
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. */ | |
d560a41c | 2619 | if (cfun->rtl_inline_init) |
ddc9542b | 2620 | return 0; |
d560a41c | 2621 | cfun->rtl_inline_init = 1; |
ddc9542b AH |
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; | |
48aba75b | 2639 | |
ddc9542b AH |
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 | { | |
b6fe0bb8 GDR |
2649 | if (warn_inline && lose && DECL_INLINE (decl)) |
2650 | { | |
ddd2d57e RH |
2651 | char *msg = concat ("%J", lose, NULL); |
2652 | warning (msg, decl); | |
b6fe0bb8 GDR |
2653 | free (msg); |
2654 | } | |
ddc9542b AH |
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)) | |
48aba75b | 2660 | { |
ddc9542b AH |
2661 | DECL_INITIAL (decl) = 0; |
2662 | return true; | |
48aba75b | 2663 | } |
854a97f0 | 2664 | } |
b3c3af2f | 2665 | else |
ddc9542b | 2666 | inlinable = DECL_INLINE (decl) = 1; |
a01da83b | 2667 | } |
a18820c6 | 2668 | |
ddc9542b AH |
2669 | insns = get_insns (); |
2670 | ||
2671 | /* Dump the rtl code if we are dumping rtl. */ | |
4291d9c8 | 2672 | |
ddc9542b | 2673 | if (open_dump_file (DFI_rtl, decl)) |
4291d9c8 | 2674 | { |
d560a41c | 2675 | if (DECL_SAVED_INSNS (decl) && DECL_SAVED_INSNS (decl)->saved_for_inline) |
ddc9542b AH |
2676 | fprintf (rtl_dump_file, ";; (integrable)\n\n"); |
2677 | close_dump_file (DFI_rtl, print_rtl, insns); | |
2678 | } | |
5e1afb11 | 2679 | |
ddc9542b AH |
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; | |
854a97f0 | 2700 | |
ddc9542b AH |
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) | |
2a9a326b | 2716 | { |
ddc9542b | 2717 | int saved_optimize = optimize; |
01f62f01 | 2718 | |
ddc9542b AH |
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; | |
c6a26dc4 | 2725 | |
ddc9542b AH |
2726 | /* CFG is no longer maintained up-to-date. */ |
2727 | free_bb_for_insn (); | |
2a9a326b | 2728 | } |
a3770a81 | 2729 | |
ddc9542b AH |
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; | |
4291d9c8 RS |
2741 | } |
2742 | ||
ddc9542b AH |
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 | } | |
a0134312 | 2748 | |
ddc9542b AH |
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); | |
a0134312 | 2755 | |
ddc9542b AH |
2756 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); |
2757 | convert_to_ssa (); | |
a0134312 | 2758 | |
ddc9542b AH |
2759 | close_dump_file (DFI_ssa, print_rtl_with_bb, insns); |
2760 | timevar_pop (TV_TO_SSA); | |
a0134312 | 2761 | |
ddc9542b AH |
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); | |
a0134312 | 2767 | |
ddc9542b AH |
2768 | ssa_const_prop (); |
2769 | ||
2770 | close_dump_file (DFI_ssa_ccp, print_rtl_with_bb, get_insns ()); | |
2771 | timevar_pop (TV_SSA_CCP); | |
a0134312 RS |
2772 | } |
2773 | ||
ddc9542b AH |
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. */ | |
38c1593d | 2777 | |
ddc9542b AH |
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. */ | |
38c1593d | 2782 | |
ddc9542b AH |
2783 | if (flag_ssa_dce) |
2784 | { | |
2785 | /* Remove dead code. */ | |
38c1593d | 2786 | |
ddc9542b AH |
2787 | timevar_push (TV_SSA_DCE); |
2788 | open_dump_file (DFI_ssa_dce, decl); | |
38c1593d | 2789 | |
ddc9542b AH |
2790 | insns = get_insns (); |
2791 | ssa_eliminate_dead_code (); | |
38c1593d | 2792 | |
ddc9542b AH |
2793 | close_dump_file (DFI_ssa_dce, print_rtl_with_bb, insns); |
2794 | timevar_pop (TV_SSA_DCE); | |
2795 | } | |
38c1593d | 2796 | |
ddc9542b | 2797 | /* Convert from SSA form. */ |
38c1593d | 2798 | |
ddc9542b AH |
2799 | timevar_push (TV_FROM_SSA); |
2800 | open_dump_file (DFI_ussa, decl); | |
38c1593d | 2801 | |
ddc9542b AH |
2802 | convert_from_ssa (); |
2803 | /* New registers have been created. Rescan their usage. */ | |
2804 | reg_scan (insns, max_reg_num (), 1); | |
7e51e626 | 2805 | |
ddc9542b AH |
2806 | close_dump_file (DFI_ussa, print_rtl_with_bb, insns); |
2807 | timevar_pop (TV_FROM_SSA); | |
38c1593d | 2808 | |
ddc9542b AH |
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); | |
38c1593d | 2850 | } |
ddc9542b AH |
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) | |
0fb53e68 | 2875 | { |
ddc9542b AH |
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 ()) | |
fc8dfa20 | 2884 | { |
ddc9542b AH |
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); | |
fc8dfa20 | 2891 | } |
ddc9542b AH |
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); | |
0b75beaa EB |
2919 | if (purge_all_dead_edges (0)) |
2920 | delete_unreachable_blocks (); | |
ddc9542b AH |
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 | { | |
fc8dfa20 | 2933 | timevar_push (TV_JUMP); |
ddc9542b AH |
2934 | |
2935 | if (delete_null_pointer_checks (insns)) | |
2936 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
fc8dfa20 | 2937 | timevar_pop (TV_JUMP); |
0fb53e68 | 2938 | } |
ddc9542b AH |
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) | |
5c856b23 | 2964 | { |
ddc9542b AH |
2965 | timevar_push (TV_JUMP); |
2966 | rebuild_jump_labels (insns); | |
5c856b23 | 2967 | cleanup_cfg (CLEANUP_EXPENSIVE); |
ddc9542b | 2968 | timevar_pop (TV_JUMP); |
5c856b23 | 2969 | } |
ddc9542b AH |
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 | } | |
38c1593d | 2975 | |
ddc9542b AH |
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; | |
617b465c | 2982 | |
ddc9542b AH |
2983 | timevar_push (TV_GCSE); |
2984 | open_dump_file (DFI_gcse, decl); | |
617b465c | 2985 | |
ddc9542b AH |
2986 | tem = gcse_main (insns, rtl_dump_file); |
2987 | rebuild_jump_labels (insns); | |
2988 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
617b465c | 2989 | |
ddc9542b AH |
2990 | save_csb = flag_cse_skip_blocks; |
2991 | save_cfj = flag_cse_follow_jumps; | |
2992 | flag_cse_skip_blocks = flag_cse_follow_jumps = 0; | |
b17d5d7c | 2993 | |
ddc9542b AH |
2994 | /* Instantiate any remaining CONSTANT_P_RTX nodes. */ |
2995 | if (current_function_calls_constant_p) | |
2996 | purge_builtin_constant_p (); | |
617b465c | 2997 | |
ddc9542b AH |
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); | |
617b465c | 3006 | delete_trivially_dead_insns (insns, max_reg_num ()); |
ddc9542b AH |
3007 | timevar_pop (TV_CSE); |
3008 | cse_not_expected = !flag_rerun_cse_after_loop; | |
617b465c ZD |
3009 | } |
3010 | ||
ddc9542b AH |
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) | |
c2f006ec | 3014 | { |
ddc9542b AH |
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); | |
735a0e33 | 3020 | |
ddc9542b | 3021 | if (flag_expensive_optimizations) |
032713aa | 3022 | { |
ddc9542b AH |
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); | |
032713aa | 3029 | } |
032713aa | 3030 | } |
735a0e33 | 3031 | |
ddc9542b AH |
3032 | close_dump_file (DFI_gcse, print_rtl_with_bb, insns); |
3033 | timevar_pop (TV_GCSE); | |
4291d9c8 | 3034 | |
ddc9542b AH |
3035 | ggc_collect (); |
3036 | flag_cse_skip_blocks = save_csb; | |
3037 | flag_cse_follow_jumps = save_cfj; | |
38c1593d JH |
3038 | #ifdef ENABLE_CHECKING |
3039 | verify_flow_info (); | |
3040 | #endif | |
ddc9542b AH |
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 | ||
e0bb17a8 | 3093 | /* Perform loop optimizations. It might be better to do them a bit |
ddc9542b AH |
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 | { | |
e0bb17a8 | 3109 | /* The optimizations: */ |
ddc9542b AH |
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 | |
e25a75e6 | 3139 | rest_of_compilation (tree decl) |
ddc9542b AH |
3140 | { |
3141 | rtx insns; | |
3142 | int rebuild_label_notes_after_reload; | |
3143 | ||
3144 | timevar_push (TV_REST_OF_COMPILATION); | |
3145 | ||
9ee634e3 JH |
3146 | /* Register rtl specific functions for cfg. */ |
3147 | rtl_register_cfg_hooks (); | |
3148 | ||
ddc9542b AH |
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. */ | |
1bb17c21 | 3186 | if (cgraph_function_possibly_inlined_p (decl)) |
ddc9542b AH |
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 | ||
0435312e | 3245 | insn_locators_initialize (); |
ddc9542b AH |
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)); | |
5ece9746 | 3308 | |
ddc9542b | 3309 | if (optimize) |
d29c259b | 3310 | { |
ddc9542b AH |
3311 | free_bb_for_insn (); |
3312 | copy_loop_headers (insns); | |
3313 | find_basic_blocks (insns, max_reg_num (), rtl_dump_file); | |
4291d9c8 | 3314 | } |
ddc9542b AH |
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); | |
4291d9c8 | 3331 | |
0626ef8a | 3332 | if (optimize) |
ddc9542b | 3333 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); |
0626ef8a | 3334 | |
ddc9542b AH |
3335 | if (flag_delete_null_pointer_checks) |
3336 | rest_of_handle_null_pointer (decl, insns); | |
6ff76c36 | 3337 | |
ddc9542b AH |
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); | |
735a0e33 | 3347 | |
1f8f4a0b | 3348 | ggc_collect (); |
a3770a81 | 3349 | |
ddc9542b AH |
3350 | if (optimize > 0) |
3351 | rest_of_handle_cse (decl, insns); | |
3352 | ||
f129791c | 3353 | rest_of_handle_addressof (decl, insns); |
ddc9542b AH |
3354 | |
3355 | ggc_collect (); | |
4291d9c8 RS |
3356 | |
3357 | if (optimize > 0) | |
032713aa | 3358 | { |
ddc9542b AH |
3359 | if (flag_gcse) |
3360 | rest_of_handle_gcse (decl, insns); | |
44a76fc8 | 3361 | |
ddc9542b AH |
3362 | if (flag_loop_optimize) |
3363 | rest_of_handle_loop_optimize (decl, insns); | |
61098249 | 3364 | |
ddc9542b AH |
3365 | if (flag_gcse) |
3366 | rest_of_handle_jump_bypass (decl, insns); | |
3367 | } | |
854a97f0 | 3368 | |
ddc9542b | 3369 | timevar_push (TV_FLOW); |
9ec6d7ab | 3370 | |
ddc9542b | 3371 | rest_of_handle_cfg (decl, insns); |
735a0e33 | 3372 | |
ddc9542b AH |
3373 | if (optimize > 0 |
3374 | || profile_arc_flag || flag_test_coverage || flag_branch_probabilities) | |
fca9dc00 ZD |
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 | } | |
a3770a81 | 3387 | |
ddc9542b AH |
3388 | if (optimize > 0) |
3389 | rest_of_handle_if_conversion (decl, insns); | |
8c660648 | 3390 | |
ddc9542b AH |
3391 | if (flag_tracer) |
3392 | rest_of_handle_tracer (decl, insns); | |
9ec6d7ab | 3393 | |
ddc9542b AH |
3394 | if (optimize > 0 |
3395 | && (flag_unswitch_loops | |
3396 | || flag_peel_loops | |
3397 | || flag_unroll_loops)) | |
3398 | rest_of_handle_loop2 (decl, insns); | |
9ec6d7ab | 3399 | |
d4d1ebc1 JH |
3400 | if (flag_web) |
3401 | rest_of_handle_web (decl, insns); | |
3402 | ||
ddc9542b AH |
3403 | if (flag_rerun_cse_after_loop) |
3404 | rest_of_handle_cse2 (decl, insns); | |
9ec6d7ab | 3405 | |
ddc9542b | 3406 | cse_not_expected = 1; |
735a0e33 | 3407 | |
ddc9542b | 3408 | rest_of_handle_life (decl, insns); |
735a0e33 | 3409 | |
ddc9542b AH |
3410 | if (optimize > 0) |
3411 | rest_of_handle_combine (decl, insns); | |
a3770a81 | 3412 | |
ddc9542b AH |
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); | |
8c660648 | 3418 | |
22fb740d JH |
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 | ||
97d36f45 | 3423 | #ifdef OPTIMIZE_MODE_SWITCHING |
b932f770 | 3424 | timevar_push (TV_MODE_SWITCH); |
97d36f45 | 3425 | |
22fb740d | 3426 | no_new_pseudos = 0; |
38c1593d | 3427 | optimize_mode_switching (NULL); |
22fb740d | 3428 | no_new_pseudos = 1; |
bd675859 | 3429 | |
b932f770 | 3430 | timevar_pop (TV_MODE_SWITCH); |
97d36f45 | 3431 | #endif |
9f09b1f2 | 3432 | |
2382b79f RS |
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 | ||
a2f8629a | 3438 | #ifdef INSN_SCHEDULING |
ddc9542b | 3439 | rest_of_handle_sched (decl, insns); |
a2f8629a | 3440 | #endif |
4291d9c8 | 3441 | |
54ff41b7 JW |
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 | ||
2a9a326b | 3447 | timevar_push (TV_LOCAL_ALLOC); |
61098249 | 3448 | open_dump_file (DFI_lreg, decl); |
246fd41f | 3449 | |
ed8d2920 MM |
3450 | if (flag_new_regalloc) |
3451 | { | |
ddc9542b AH |
3452 | if (rest_of_handle_new_regalloc (decl, insns, |
3453 | &rebuild_label_notes_after_reload)) | |
3454 | goto exit_rest_of_compilation; | |
032713aa | 3455 | } |
ed8d2920 MM |
3456 | else |
3457 | { | |
ddc9542b AH |
3458 | if (rest_of_handle_old_regalloc (decl, insns, |
3459 | &rebuild_label_notes_after_reload)) | |
ed8d2920 MM |
3460 | goto exit_rest_of_compilation; |
3461 | } | |
ab40ad2b | 3462 | |
1f8f4a0b | 3463 | ggc_collect (); |
a3770a81 | 3464 | |
8bb16620 BS |
3465 | open_dump_file (DFI_postreload, decl); |
3466 | ||
c8ed219d RK |
3467 | /* Do a very simple CSE pass over just the hard registers. */ |
3468 | if (optimize > 0) | |
2a9a326b AS |
3469 | { |
3470 | timevar_push (TV_RELOAD_CSE_REGS); | |
3471 | reload_cse_regs (insns); | |
854a97f0 | 3472 | timevar_pop (TV_RELOAD_CSE_REGS); |
2a9a326b | 3473 | } |
c8ed219d | 3474 | |
0edaaa41 HB |
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) | |
2a9a326b AS |
3479 | { |
3480 | timevar_push (TV_JUMP); | |
3481 | ||
3482 | rebuild_jump_labels (insns); | |
44d3eb5b | 3483 | purge_all_dead_edges (0); |
2a9a326b AS |
3484 | |
3485 | timevar_pop (TV_JUMP); | |
3486 | } | |
0edaaa41 | 3487 | |
8bb16620 | 3488 | close_dump_file (DFI_postreload, print_rtl_with_bb, insns); |
e881bb1b | 3489 | |
6764d250 | 3490 | /* Re-create the death notes which were deleted during reload. */ |
2a9a326b | 3491 | timevar_push (TV_FLOW2); |
61098249 | 3492 | open_dump_file (DFI_flow2, decl); |
2a9a326b | 3493 | |
6f862f2f JH |
3494 | #ifdef ENABLE_CHECKING |
3495 | verify_flow_info (); | |
3496 | #endif | |
0005550b JH |
3497 | |
3498 | /* If optimizing, then go ahead and split insns now. */ | |
10a3fdd9 | 3499 | #ifndef STACK_REGS |
0005550b | 3500 | if (optimize > 0) |
10a3fdd9 | 3501 | #endif |
0005550b JH |
3502 | split_all_insns (0); |
3503 | ||
fe3ad572 SC |
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 | ||
f7da1e9a JH |
3515 | if (optimize) |
3516 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
19d3c25c RH |
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); | |
fe3ad572 | 3523 | epilogue_completed = 1; |
19d3c25c | 3524 | |
6764d250 | 3525 | if (optimize) |
e881bb1b | 3526 | { |
2a9a326b | 3527 | life_analysis (insns, rtl_dump_file, PROP_FINAL); |
96327cdc JH |
3528 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE |
3529 | | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0)); | |
1e7f0a48 | 3530 | |
5fa41e13 | 3531 | /* This is kind of a heuristic. We need to run combine_stack_adjustments |
f73ad30e JH |
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) | |
1e7f0a48 | 3537 | #endif |
2a9a326b | 3538 | combine_stack_adjustments (); |
1e7f0a48 | 3539 | |
1f8f4a0b | 3540 | ggc_collect (); |
e881bb1b | 3541 | } |
6764d250 | 3542 | |
56744d1a JL |
3543 | flow2_completed = 1; |
3544 | ||
61098249 | 3545 | close_dump_file (DFI_flow2, print_rtl_with_bb, insns); |
2a9a326b | 3546 | timevar_pop (TV_FLOW2); |
e881bb1b | 3547 | |
ede7cd44 RH |
3548 | #ifdef HAVE_peephole2 |
3549 | if (optimize > 0 && flag_peephole2) | |
3550 | { | |
2a9a326b | 3551 | timevar_push (TV_PEEPHOLE2); |
2a9a326b | 3552 | open_dump_file (DFI_peephole2, decl); |
9ec6d7ab | 3553 | |
2a9a326b | 3554 | peephole2_optimize (rtl_dump_file); |
ede7cd44 | 3555 | |
61098249 | 3556 | close_dump_file (DFI_peephole2, print_rtl_with_bb, insns); |
2a9a326b | 3557 | timevar_pop (TV_PEEPHOLE2); |
ede7cd44 RH |
3558 | } |
3559 | #endif | |
3560 | ||
b9422b69 JH |
3561 | if (optimize > 0) |
3562 | { | |
ddc9542b AH |
3563 | if (flag_rename_registers || flag_cprop_registers) |
3564 | rest_of_handle_regrename (decl, insns); | |
b9422b69 | 3565 | |
ddc9542b | 3566 | rest_of_handle_reorder_blocks (decl, insns); |
b9422b69 JH |
3567 | } |
3568 | ||
fa1a0d02 JH |
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 | } | |
fa1a0d02 | 3579 | |
fe3ad572 SC |
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 | ||
375e2d5c | 3598 | #ifdef INSN_SCHEDULING |
4291d9c8 | 3599 | if (optimize > 0 && flag_schedule_insns_after_reload) |
ddc9542b | 3600 | rest_of_handle_sched2 (decl, insns); |
375e2d5c | 3601 | #endif |
4291d9c8 RS |
3602 | |
3603 | #ifdef LEAF_REGISTERS | |
5ad9b85f JW |
3604 | current_function_uses_only_leaf_regs |
3605 | = optimize > 0 && only_leaf_regs_used () && leaf_function_p (); | |
4291d9c8 RS |
3606 | #endif |
3607 | ||
1e5fd094 | 3608 | #ifdef STACK_REGS |
ddc9542b | 3609 | rest_of_handle_stack_regs (decl, insns); |
1e5fd094 | 3610 | #endif |
ddc9542b | 3611 | |
247a370b | 3612 | compute_alignments (); |
11bdd2ae | 3613 | |
f5143c46 | 3614 | /* CFG is no longer maintained up-to-date. */ |
3c030e88 JH |
3615 | free_bb_for_insn (); |
3616 | ||
18dbd950 | 3617 | if (targetm.machine_dependent_reorg != 0) |
ddc9542b | 3618 | rest_of_handle_machine_reorg (decl, insns); |
2c65021a | 3619 | |
0045d504 | 3620 | purge_line_number_notes (insns); |
01f62f01 | 3621 | cleanup_barriers (); |
0045d504 | 3622 | |
4291d9c8 RS |
3623 | #ifdef DELAY_SLOTS |
3624 | if (optimize > 0 && flag_delayed_branch) | |
ddc9542b | 3625 | rest_of_handle_delay_slots (decl, insns); |
4291d9c8 RS |
3626 | #endif |
3627 | ||
1e5fd094 | 3628 | #if defined (HAVE_ATTR_length) && !defined (STACK_REGS) |
d7e5d7fe | 3629 | timevar_push (TV_SHORTEN_BRANCH); |
6f862f2f | 3630 | split_all_insns_noflow (); |
2a9a326b | 3631 | timevar_pop (TV_SHORTEN_BRANCH); |
932f0847 | 3632 | #endif |
52a11cbf RH |
3633 | |
3634 | convert_to_eh_region_ranges (); | |
932f0847 JH |
3635 | |
3636 | /* Shorten branches. */ | |
3637 | timevar_push (TV_SHORTEN_BRANCH); | |
3638 | shorten_branches (get_insns ()); | |
3639 | timevar_pop (TV_SHORTEN_BRANCH); | |
4291d9c8 | 3640 | |
b6128b8c | 3641 | set_nothrow_function_flags (); |
12a22e76 JM |
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; | |
fb13d4d0 | 3646 | |
ddc9542b | 3647 | rest_of_handle_final (decl, insns); |
a3770a81 | 3648 | |
854a97f0 | 3649 | /* Write DBX symbols if requested. */ |
4291d9c8 RS |
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;'. | |
2bb74773 DJ |
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. */ | |
4291d9c8 | 3659 | |
2a9a326b | 3660 | timevar_push (TV_SYMOUT); |
2b85879e | 3661 | (*debug_hooks->function_decl) (decl); |
2a9a326b | 3662 | timevar_pop (TV_SYMOUT); |
9a666dda | 3663 | |
4291d9c8 RS |
3664 | exit_rest_of_compilation: |
3665 | ||
ca29da43 | 3666 | coverage_end_function (); |
e25a75e6 | 3667 | |
f246a305 RS |
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) | |
37366632 | 3673 | sdbout_types (NULL_TREE); |
f246a305 RS |
3674 | #endif |
3675 | ||
4291d9c8 | 3676 | reload_completed = 0; |
fe3ad572 | 3677 | epilogue_completed = 0; |
56744d1a | 3678 | flow2_completed = 0; |
f1db3576 | 3679 | no_new_pseudos = 0; |
4291d9c8 | 3680 | |
2a9a326b | 3681 | timevar_push (TV_FINAL); |
4291d9c8 | 3682 | |
2a9a326b AS |
3683 | /* Clear out the insn_length contents now that they are no |
3684 | longer valid. */ | |
3685 | init_insn_lengths (); | |
3686 | ||
2a9a326b AS |
3687 | /* Show no temporary slots allocated. */ |
3688 | init_temp_slots (); | |
adcd38c9 | 3689 | |
2a9a326b | 3690 | free_basic_block_vars (0); |
5652450c | 3691 | free_bb_for_insn (); |
fa51b01b | 3692 | |
2a9a326b | 3693 | timevar_pop (TV_FINAL); |
adcd38c9 | 3694 | |
b255a036 JH |
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 | ||
c8d86b9a JW |
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 | ||
21cd906e | 3716 | /* We're done with this function. Free up memory if we can. */ |
01d939e8 | 3717 | free_after_parsing (cfun); |
fa51b01b | 3718 | if (! DECL_DEFER_OUTPUT (decl)) |
ae6f2a1c ZW |
3719 | { |
3720 | free_after_compilation (cfun); | |
ae6f2a1c ZW |
3721 | DECL_SAVED_INSNS (decl) = 0; |
3722 | } | |
01d939e8 | 3723 | cfun = 0; |
a3770a81 | 3724 | |
1f8f4a0b | 3725 | ggc_collect (); |
a3770a81 | 3726 | |
2a9a326b | 3727 | timevar_pop (TV_REST_OF_COMPILATION); |
4291d9c8 | 3728 | } |
ddc9542b | 3729 | |
ddc9542b | 3730 | /* Display help for target options. */ |
d185d268 | 3731 | void |
e25a75e6 | 3732 | display_target_options (void) |
10501d8f | 3733 | { |
a01da83b | 3734 | int undoc, i; |
76306300 NB |
3735 | static bool displayed = false; |
3736 | ||
3737 | /* Avoid double printing for --help --target-help. */ | |
3738 | if (displayed) | |
3739 | return; | |
d185d268 | 3740 | |
76306300 | 3741 | displayed = true; |
10501d8f | 3742 | |
b6a1cbae | 3743 | if (ARRAY_SIZE (target_switches) > 1 |
b8468bc7 | 3744 | #ifdef TARGET_OPTIONS |
b6a1cbae | 3745 | || ARRAY_SIZE (target_options) > 1 |
b8468bc7 NC |
3746 | #endif |
3747 | ) | |
3748 | { | |
3749 | int doc = 0; | |
854a97f0 | 3750 | |
b8468bc7 | 3751 | undoc = 0; |
854a97f0 | 3752 | |
5e4adfba | 3753 | printf (_("\nTarget specific options:\n")); |
b8468bc7 | 3754 | |
b6a1cbae | 3755 | for (i = ARRAY_SIZE (target_switches); i--;) |
b8468bc7 | 3756 | { |
854a97f0 KH |
3757 | const char *option = target_switches[i].name; |
3758 | const char *description = target_switches[i].description; | |
b8468bc7 | 3759 | |
854a97f0 | 3760 | if (option == NULL || *option == 0) |
b8468bc7 NC |
3761 | continue; |
3762 | else if (description == NULL) | |
844642e6 NC |
3763 | { |
3764 | undoc = 1; | |
854a97f0 | 3765 | |
844642e6 | 3766 | if (extra_warnings) |
7eaab492 | 3767 | printf (_(" -m%-23s [undocumented]\n"), option); |
844642e6 | 3768 | } |
9cabb1d8 | 3769 | else if (*description != 0) |
7eaab492 | 3770 | doc += printf (" -m%-23s %s\n", option, _(description)); |
b8468bc7 | 3771 | } |
854a97f0 KH |
3772 | |
3773 | #ifdef TARGET_OPTIONS | |
b6a1cbae | 3774 | for (i = ARRAY_SIZE (target_options); i--;) |
b8468bc7 | 3775 | { |
854a97f0 KH |
3776 | const char *option = target_options[i].prefix; |
3777 | const char *description = target_options[i].description; | |
b8468bc7 | 3778 | |
854a97f0 | 3779 | if (option == NULL || *option == 0) |
b8468bc7 NC |
3780 | continue; |
3781 | else if (description == NULL) | |
844642e6 NC |
3782 | { |
3783 | undoc = 1; | |
854a97f0 | 3784 | |
844642e6 | 3785 | if (extra_warnings) |
7eaab492 | 3786 | printf (_(" -m%-23s [undocumented]\n"), option); |
844642e6 | 3787 | } |
9cabb1d8 | 3788 | else if (*description != 0) |
7eaab492 | 3789 | doc += printf (" -m%-23s %s\n", option, _(description)); |
b8468bc7 NC |
3790 | } |
3791 | #endif | |
3792 | if (undoc) | |
ff59bfe6 JM |
3793 | { |
3794 | if (doc) | |
5e4adfba | 3795 | printf (_("\nThere are undocumented target specific options as well.\n")); |
ff59bfe6 | 3796 | else |
5e4adfba | 3797 | printf (_(" They exist, but they are not documented.\n")); |
ff59bfe6 | 3798 | } |
b8468bc7 NC |
3799 | } |
3800 | } | |
ddc9542b | 3801 | |
f63d1bf7 | 3802 | /* Parse a -d... command line switch. */ |
39dd8003 | 3803 | |
d185d268 | 3804 | void |
e25a75e6 | 3805 | decode_d_option (const char *arg) |
39dd8003 | 3806 | { |
61098249 RH |
3807 | int i, c, matched; |
3808 | ||
3809 | while (*arg) | |
3810 | switch (c = *arg++) | |
39dd8003 NC |
3811 | { |
3812 | case 'a': | |
dbbbbf3b | 3813 | for (i = 0; i < (int) DFI_MAX; ++i) |
61098249 | 3814 | dump_file[i].enabled = 1; |
39dd8003 NC |
3815 | break; |
3816 | case 'A': | |
3817 | flag_debug_asm = 1; | |
3818 | break; | |
39dd8003 NC |
3819 | case 'p': |
3820 | flag_print_asm_name = 1; | |
3821 | break; | |
c349e40b | 3822 | case 'P': |
9cabb1d8 KH |
3823 | flag_dump_rtl_in_asm = 1; |
3824 | flag_print_asm_name = 1; | |
3825 | break; | |
39dd8003 NC |
3826 | case 'v': |
3827 | graph_dump_format = vcg; | |
3828 | break; | |
39dd8003 NC |
3829 | case 'x': |
3830 | rtl_dump_and_exit = 1; | |
3831 | break; | |
3832 | case 'y': | |
ff45c01e | 3833 | set_yydebug = 1; |
39dd8003 | 3834 | break; |
39dd8003 NC |
3835 | case 'D': /* These are handled by the preprocessor. */ |
3836 | case 'I': | |
3837 | break; | |
886e0865 GK |
3838 | case 'H': |
3839 | setup_core_dumping(); | |
3840 | break; | |
61098249 | 3841 | |
39dd8003 | 3842 | default: |
61098249 | 3843 | matched = 0; |
dbbbbf3b | 3844 | for (i = 0; i < (int) DFI_MAX; ++i) |
61098249 RH |
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); | |
39dd8003 NC |
3853 | break; |
3854 | } | |
3855 | } | |
b8468bc7 | 3856 | |
df026186 GK |
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 | ||
f5e99456 NB |
3863 | /* Decode -m switches. */ |
3864 | /* Decode the switch -mNAME. */ | |
7adfcfed | 3865 | |
903caebf | 3866 | void |
e25a75e6 | 3867 | set_target_switch (const char *name) |
4291d9c8 | 3868 | { |
f5e99456 NB |
3869 | size_t j; |
3870 | int valid_target_option = 0; | |
4291d9c8 | 3871 | |
f5e99456 NB |
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; | |
a27fb29b RS |
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 | } | |
f5e99456 NB |
3886 | valid_target_option = 1; |
3887 | } | |
4291d9c8 | 3888 | |
f5e99456 NB |
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); | |
c409ea0d | 3894 | if (target_options[j].value) |
f5e99456 | 3895 | { |
c409ea0d DD |
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 | } | |
f5e99456 NB |
3909 | } |
3910 | } | |
3911 | #endif | |
4291d9c8 | 3912 | |
f5e99456 | 3913 | if (!valid_target_option) |
1f978f5f | 3914 | error ("invalid option `%s'", name); |
f5e99456 | 3915 | } |
ddc9542b | 3916 | |
f5e99456 NB |
3917 | /* Print version information to FILE. |
3918 | Each line begins with INDENT (for the case where FILE is the | |
3919 | assembler output file). */ | |
3920 | ||
d185d268 | 3921 | void |
e25a75e6 | 3922 | print_version (FILE *file, const char *indent) |
f5e99456 NB |
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__); | |
7a69a172 GB |
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)); | |
f5e99456 NB |
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 | |
e25a75e6 AJ |
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) | |
f5e99456 NB |
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 | |
e25a75e6 AJ |
3976 | print_switch_values (FILE *file, int pos, int max, |
3977 | const char *indent, const char *sep, const char *term) | |
f5e99456 NB |
3978 | { |
3979 | size_t j; | |
b86f6cd9 | 3980 | const char **p; |
f5e99456 | 3981 | |
a37db56b | 3982 | /* Fill in the -frandom-seed option, if the user didn't pass it, so |
c07e5477 NS |
3983 | that it can be printed below. This helps reproducibility. */ |
3984 | randomize (); | |
a37db56b | 3985 | |
f5e99456 | 3986 | /* Print the options as passed. */ |
f5e99456 NB |
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 | } | |
ddc9542b | 4049 | |
f5e99456 NB |
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 | |
e25a75e6 | 4055 | init_asm_output (const char *name) |
f5e99456 NB |
4056 | { |
4057 | if (name == NULL && asm_file_name == 0) | |
4058 | asm_out_file = stdout; | |
4059 | else | |
4060 | { | |
4061 | if (asm_file_name == 0) | |
9cabb1d8 KH |
4062 | { |
4063 | int len = strlen (dump_base_name); | |
703ad42b | 4064 | char *dumpname = xmalloc (len + 6); |
9cabb1d8 KH |
4065 | memcpy (dumpname, dump_base_name, len + 1); |
4066 | strip_off_ending (dumpname, len); | |
4067 | strcat (dumpname, ".s"); | |
4068 | asm_file_name = dumpname; | |
4069 | } | |
f5e99456 | 4070 | if (!strcmp (asm_file_name, "-")) |
9cabb1d8 | 4071 | asm_out_file = stdout; |
f5e99456 | 4072 | else |
17211ab5 | 4073 | asm_out_file = fopen (asm_file_name, "w+"); |
f5e99456 | 4074 | if (asm_out_file == 0) |
fa6ef813 | 4075 | fatal_error ("can't open %s for writing: %m", asm_file_name); |
f5e99456 NB |
4076 | } |
4077 | ||
4078 | #ifdef IO_BUFFER_SIZE | |
703ad42b | 4079 | setvbuf (asm_out_file, xmalloc (IO_BUFFER_SIZE), |
9cabb1d8 | 4080 | _IOFBF, IO_BUFFER_SIZE); |
f5e99456 NB |
4081 | #endif |
4082 | ||
4083 | if (!flag_syntax_only) | |
4084 | { | |
1bc7c5b6 | 4085 | targetm.asm_out.file_start (); |
f5e99456 NB |
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 | } | |
ddc9542b | 4101 | |
7bb1ad93 GK |
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 | { | |
2b256a46 | 4109 | #ifdef TARGET_OPTIONS |
7bb1ad93 | 4110 | size_t i; |
2b256a46 | 4111 | #endif |
7bb1ad93 GK |
4112 | char *result, *r; |
4113 | ||
4114 | *len = sizeof (target_flags) + 2; | |
b36c208a | 4115 | #ifdef TARGET_OPTIONS |
7bb1ad93 GK |
4116 | for (i = 0; i < ARRAY_SIZE (target_options); i++) |
4117 | { | |
4118 | *len += 1; | |
4119 | if (*target_options[i].variable) | |
4120 | *len += strlen (*target_options[i].variable); | |
4121 | } | |
b36c208a | 4122 | #endif |
7bb1ad93 GK |
4123 | |
4124 | result = r = xmalloc (*len); | |
4125 | r[0] = flag_pic; | |
4126 | r[1] = flag_pie; | |
4127 | r += 2; | |
4128 | memcpy (r, &target_flags, sizeof (target_flags)); | |
4129 | r += sizeof (target_flags); | |
4130 | ||
b36c208a | 4131 | #ifdef TARGET_OPTIONS |
7bb1ad93 GK |
4132 | for (i = 0; i < ARRAY_SIZE (target_options); i++) |
4133 | { | |
4134 | const char *str = *target_options[i].variable; | |
4135 | size_t l; | |
4136 | if (! str) | |
4137 | str = ""; | |
4138 | l = strlen (str) + 1; | |
4139 | memcpy (r, str, l); | |
4140 | r += l; | |
4141 | } | |
b36c208a | 4142 | #endif |
7bb1ad93 GK |
4143 | |
4144 | return result; | |
4145 | } | |
4146 | ||
4147 | /* Default version of pch_valid_p. */ | |
4148 | ||
4149 | const char * | |
4150 | default_pch_valid_p (const void *data_p, size_t len) | |
4151 | { | |
4152 | const char *data = (const char *)data_p; | |
4153 | const char *flag_that_differs = NULL; | |
4154 | size_t i; | |
4155 | ||
4156 | /* -fpic and -fpie also usually make a PCH invalid. */ | |
4157 | if (data[0] != flag_pic) | |
4158 | return _("created and used with different settings of -fpic"); | |
4159 | if (data[1] != flag_pie) | |
4160 | return _("created and used with different settings of -fpie"); | |
4161 | data += 2; | |
4162 | ||
4163 | /* Check target_flags. */ | |
4164 | if (memcmp (data, &target_flags, sizeof (target_flags)) != 0) | |
4165 | { | |
4166 | for (i = 0; i < ARRAY_SIZE (target_switches); i++) | |
4167 | { | |
4168 | int bits; | |
4169 | int tf; | |
4170 | ||
4171 | memcpy (&tf, data, sizeof (target_flags)); | |
4172 | ||
4173 | bits = target_switches[i].value; | |
4174 | if (bits < 0) | |
4175 | bits = -bits; | |
4176 | if ((target_flags & bits) != (tf & bits)) | |
4177 | { | |
4178 | flag_that_differs = target_switches[i].name; | |
4179 | goto make_message; | |
4180 | } | |
4181 | } | |
4182 | abort (); | |
4183 | } | |
4184 | data += sizeof (target_flags); | |
4185 | len -= sizeof (target_flags); | |
4186 | ||
4187 | /* Check string options. */ | |
b36c208a | 4188 | #ifdef TARGET_OPTIONS |
7bb1ad93 GK |
4189 | for (i = 0; i < ARRAY_SIZE (target_options); i++) |
4190 | { | |
4191 | const char *str = *target_options[i].variable; | |
4192 | size_t l; | |
4193 | if (! str) | |
4194 | str = ""; | |
4195 | l = strlen (str) + 1; | |
4196 | if (len < l || memcmp (data, str, l) != 0) | |
4197 | { | |
4198 | flag_that_differs = target_options[i].prefix; | |
4199 | goto make_message; | |
4200 | } | |
4201 | data += l; | |
4202 | len -= l; | |
4203 | } | |
b36c208a | 4204 | #endif |
7bb1ad93 GK |
4205 | |
4206 | return NULL; | |
4207 | ||
4208 | make_message: | |
4209 | { | |
4210 | char *r; | |
4211 | asprintf (&r, _("created and used with differing settings of `-m%s'"), | |
4212 | flag_that_differs); | |
4213 | if (r == NULL) | |
d7d4cd78 | 4214 | return _("out of memory"); |
7bb1ad93 GK |
4215 | return r; |
4216 | } | |
4217 | } | |
4218 | ||
b6fe0bb8 GDR |
4219 | /* Default tree printer. Handles declarations only. */ |
4220 | static bool | |
4221 | default_tree_printer (pretty_printer * pp, text_info *text) | |
4222 | { | |
4223 | switch (*text->format_spec) | |
4224 | { | |
4225 | case 'D': | |
4226 | case 'F': | |
4227 | case 'T': | |
4228 | { | |
4229 | tree t = va_arg (*text->args_ptr, tree); | |
4230 | const char *n = DECL_NAME (t) | |
4231 | ? (*lang_hooks.decl_printable_name) (t, 2) | |
4232 | : "<anonymous>"; | |
4233 | pp_string (pp, n); | |
4234 | } | |
4235 | return true; | |
4236 | ||
4237 | default: | |
4238 | return false; | |
4239 | } | |
4240 | } | |
4241 | ||
f5e99456 NB |
4242 | /* Initialization of the front end environment, before command line |
4243 | options are parsed. Signal handlers, internationalization etc. | |
4244 | ARGV0 is main's argv[0]. */ | |
4245 | static void | |
b86f6cd9 | 4246 | general_init (const char *argv0) |
f5e99456 | 4247 | { |
b86f6cd9 | 4248 | const char *p; |
f5e99456 NB |
4249 | |
4250 | p = argv0 + strlen (argv0); | |
4251 | while (p != argv0 && !IS_DIR_SEPARATOR (p[-1])) | |
4252 | --p; | |
4253 | progname = p; | |
4254 | ||
4255 | xmalloc_set_program_name (progname); | |
e1a132c6 | 4256 | |
5351f1ca NB |
4257 | hex_init (); |
4258 | ||
191bf464 | 4259 | gcc_init_libintl (); |
ab87f8c8 | 4260 | |
b6fe0bb8 GDR |
4261 | /* Initialize the diagnostics reporting machinery, so option parsing |
4262 | can give warnings and errors. */ | |
4263 | diagnostic_initialize (global_dc); | |
4264 | /* Set a default printer. Language specific initializations will | |
4265 | override it later. */ | |
4266 | pp_format_decoder (global_dc->printer) = &default_tree_printer; | |
4267 | ||
a7023245 ZW |
4268 | /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */ |
4269 | #ifdef SIGSEGV | |
4270 | signal (SIGSEGV, crash_signal); | |
935d4b07 | 4271 | #endif |
a7023245 ZW |
4272 | #ifdef SIGILL |
4273 | signal (SIGILL, crash_signal); | |
4274 | #endif | |
4275 | #ifdef SIGBUS | |
4276 | signal (SIGBUS, crash_signal); | |
4277 | #endif | |
4278 | #ifdef SIGABRT | |
4279 | signal (SIGABRT, crash_signal); | |
4280 | #endif | |
4281 | #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT) | |
4282 | signal (SIGIOT, crash_signal); | |
4283 | #endif | |
15e5ad76 ZW |
4284 | #ifdef SIGFPE |
4285 | signal (SIGFPE, crash_signal); | |
4286 | #endif | |
854a97f0 | 4287 | |
476d9098 GK |
4288 | /* Other host-specific signal setup. */ |
4289 | (*host_hooks.extra_signals)(); | |
4290 | ||
c79043f3 NB |
4291 | /* Initialize the garbage-collector, string pools and tree type hash |
4292 | table. */ | |
4293 | init_ggc (); | |
4294 | init_stringpool (); | |
4295 | init_ttree (); | |
6a08f7b3 | 4296 | |
f5e99456 NB |
4297 | /* Initialize register usage now so switches may override. */ |
4298 | init_reg_sets (); | |
764dbbf2 | 4299 | |
c6d9a88c MM |
4300 | /* Register the language-independent parameters. */ |
4301 | add_params (lang_independent_params, LAST_PARAM); | |
4302 | ||
9ac121af KG |
4303 | /* This must be done after add_params but before argument processing. */ |
4304 | init_ggc_heuristics(); | |
a32274ad | 4305 | } |
ddc9542b | 4306 | |
a32274ad NB |
4307 | /* Process the options that have been parsed. */ |
4308 | static void | |
e25a75e6 | 4309 | process_options (void) |
a32274ad | 4310 | { |
4bfec483 NB |
4311 | /* Allow the front end to perform consistency checks and do further |
4312 | initialization based on the command line options. This hook also | |
4313 | sets the original filename if appropriate (e.g. foo.i -> foo.c) | |
4314 | so we can correctly initialize debug output. */ | |
d7b42618 NB |
4315 | no_backend = (*lang_hooks.post_options) (&main_input_filename); |
4316 | input_filename = main_input_filename; | |
4bfec483 | 4317 | |
4291d9c8 RS |
4318 | #ifdef OVERRIDE_OPTIONS |
4319 | /* Some machines may reject certain combinations of options. */ | |
4320 | OVERRIDE_OPTIONS; | |
4321 | #endif | |
4322 | ||
b1cbe78c NB |
4323 | /* Set aux_base_name if not already set. */ |
4324 | if (aux_base_name) | |
4325 | ; | |
d7b42618 | 4326 | else if (main_input_filename) |
b1cbe78c | 4327 | { |
d7b42618 | 4328 | char *name = xstrdup (lbasename (main_input_filename)); |
e25a75e6 | 4329 | |
b1cbe78c NB |
4330 | strip_off_ending (name, strlen (name)); |
4331 | aux_base_name = name; | |
4332 | } | |
4333 | else | |
4334 | aux_base_name = "gccaux"; | |
4335 | ||
efa3896a GK |
4336 | /* Set up the align_*_log variables, defaulting them to 1 if they |
4337 | were still unset. */ | |
4338 | if (align_loops <= 0) align_loops = 1; | |
2cca7283 JH |
4339 | if (align_loops_max_skip > align_loops || !align_loops) |
4340 | align_loops_max_skip = align_loops - 1; | |
854a97f0 | 4341 | align_loops_log = floor_log2 (align_loops * 2 - 1); |
efa3896a | 4342 | if (align_jumps <= 0) align_jumps = 1; |
2cca7283 JH |
4343 | if (align_jumps_max_skip > align_jumps || !align_jumps) |
4344 | align_jumps_max_skip = align_jumps - 1; | |
854a97f0 | 4345 | align_jumps_log = floor_log2 (align_jumps * 2 - 1); |
efa3896a | 4346 | if (align_labels <= 0) align_labels = 1; |
854a97f0 | 4347 | align_labels_log = floor_log2 (align_labels * 2 - 1); |
2cca7283 JH |
4348 | if (align_labels_max_skip > align_labels || !align_labels) |
4349 | align_labels_max_skip = align_labels - 1; | |
efa3896a | 4350 | if (align_functions <= 0) align_functions = 1; |
854a97f0 KH |
4351 | align_functions_log = floor_log2 (align_functions * 2 - 1); |
4352 | ||
4291d9c8 RS |
4353 | /* Unrolling all loops implies that standard loop unrolling must also |
4354 | be done. */ | |
4355 | if (flag_unroll_all_loops) | |
4356 | flag_unroll_loops = 1; | |
b17d5d7c ZD |
4357 | |
4358 | if (flag_unroll_loops) | |
4359 | { | |
4360 | flag_old_unroll_loops = 0; | |
4361 | flag_old_unroll_all_loops = 0; | |
4362 | } | |
4363 | ||
4364 | if (flag_old_unroll_all_loops) | |
4365 | flag_old_unroll_loops = 1; | |
4366 | ||
4367 | /* Old loop unrolling requires that strength_reduction be on also. Silently | |
4291d9c8 RS |
4368 | turn on strength reduction here if it isn't already on. Also, the loop |
4369 | unrolling code assumes that cse will be run after loop, so that must | |
4370 | be turned on also. */ | |
b17d5d7c | 4371 | if (flag_old_unroll_loops) |
4291d9c8 RS |
4372 | { |
4373 | flag_strength_reduce = 1; | |
4374 | flag_rerun_cse_after_loop = 1; | |
4375 | } | |
b17d5d7c ZD |
4376 | if (flag_unroll_loops || flag_peel_loops) |
4377 | flag_rerun_cse_after_loop = 1; | |
4291d9c8 | 4378 | |
b932f770 JH |
4379 | if (flag_non_call_exceptions) |
4380 | flag_asynchronous_unwind_tables = 1; | |
4381 | if (flag_asynchronous_unwind_tables) | |
4382 | flag_unwind_tables = 1; | |
4383 | ||
e72fcfe8 JH |
4384 | /* Disable unit-at-a-time mode for frontends not supporting callgraph |
4385 | interface. */ | |
4386 | if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function) | |
4387 | flag_unit_at_a_time = 0; | |
4388 | ||
fca9dc00 ZD |
4389 | if (flag_value_profile_transformations) |
4390 | flag_profile_values = 1; | |
4391 | ||
4291d9c8 RS |
4392 | /* Warn about options that are not supported on this machine. */ |
4393 | #ifndef INSN_SCHEDULING | |
4394 | if (flag_schedule_insns || flag_schedule_insns_after_reload) | |
4395 | warning ("instruction scheduling not supported on this target machine"); | |
4396 | #endif | |
4397 | #ifndef DELAY_SLOTS | |
4398 | if (flag_delayed_branch) | |
4399 | warning ("this target machine does not have delayed branches"); | |
4400 | #endif | |
4401 | ||
19283265 RH |
4402 | user_label_prefix = USER_LABEL_PREFIX; |
4403 | if (flag_leading_underscore != -1) | |
4404 | { | |
854a97f0 | 4405 | /* If the default prefix is more complicated than "" or "_", |
19283265 RH |
4406 | issue a warning and ignore this option. */ |
4407 | if (user_label_prefix[0] == 0 || | |
4408 | (user_label_prefix[0] == '_' && user_label_prefix[1] == 0)) | |
4409 | { | |
4410 | user_label_prefix = flag_leading_underscore ? "_" : ""; | |
4411 | } | |
4412 | else | |
4413 | warning ("-f%sleading-underscore not supported on this target machine", | |
4414 | flag_leading_underscore ? "" : "no-"); | |
4415 | } | |
4416 | ||
4291d9c8 RS |
4417 | /* If we are in verbose mode, write out the version and maybe all the |
4418 | option flags in use. */ | |
4419 | if (version_flag) | |
4420 | { | |
3d5cdd42 | 4421 | print_version (stderr, ""); |
4291d9c8 | 4422 | if (! quiet_flag) |
3d5cdd42 | 4423 | print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n"); |
4291d9c8 RS |
4424 | } |
4425 | ||
f5e99456 NB |
4426 | if (flag_syntax_only) |
4427 | { | |
4428 | write_symbols = NO_DEBUG; | |
4429 | profile_flag = 0; | |
f5e99456 | 4430 | } |
4291d9c8 | 4431 | |
df38ffef NB |
4432 | /* A lot of code assumes write_symbols == NO_DEBUG if the debugging |
4433 | level is 0. */ | |
4434 | if (debug_info_level == DINFO_LEVEL_NONE) | |
4435 | write_symbols = NO_DEBUG; | |
4436 | ||
f5e99456 NB |
4437 | /* Now we know write_symbols, set up the debug hooks based on it. |
4438 | By default we do nothing for debug output. */ | |
df38ffef NB |
4439 | if (write_symbols == NO_DEBUG) |
4440 | debug_hooks = &do_nothing_debug_hooks; | |
f5e99456 | 4441 | #if defined(DBX_DEBUGGING_INFO) |
df38ffef | 4442 | else if (write_symbols == DBX_DEBUG) |
f5e99456 | 4443 | debug_hooks = &dbx_debug_hooks; |
4291d9c8 | 4444 | #endif |
f5e99456 | 4445 | #if defined(XCOFF_DEBUGGING_INFO) |
df38ffef | 4446 | else if (write_symbols == XCOFF_DEBUG) |
f5e99456 | 4447 | debug_hooks = &xcoff_debug_hooks; |
3d5cdd42 | 4448 | #endif |
f5e99456 | 4449 | #ifdef SDB_DEBUGGING_INFO |
df38ffef | 4450 | else if (write_symbols == SDB_DEBUG) |
f5e99456 NB |
4451 | debug_hooks = &sdb_debug_hooks; |
4452 | #endif | |
4453 | #ifdef DWARF_DEBUGGING_INFO | |
df38ffef | 4454 | else if (write_symbols == DWARF_DEBUG) |
f5e99456 NB |
4455 | debug_hooks = &dwarf_debug_hooks; |
4456 | #endif | |
4457 | #ifdef DWARF2_DEBUGGING_INFO | |
df38ffef | 4458 | else if (write_symbols == DWARF2_DEBUG) |
f5e99456 | 4459 | debug_hooks = &dwarf2_debug_hooks; |
3d5cdd42 | 4460 | #endif |
7a0c8d71 | 4461 | #ifdef VMS_DEBUGGING_INFO |
df38ffef | 4462 | else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
7a0c8d71 DR |
4463 | debug_hooks = &vmsdbg_debug_hooks; |
4464 | #endif | |
df38ffef NB |
4465 | else |
4466 | error ("target system does not support the \"%s\" debug format", | |
4467 | debug_type_names[write_symbols]); | |
4291d9c8 | 4468 | |
f5e99456 NB |
4469 | /* If auxiliary info generation is desired, open the output file. |
4470 | This goes in the same directory as the source file--unlike | |
4471 | all the other output files. */ | |
4472 | if (flag_gen_aux_info) | |
4473 | { | |
4474 | aux_info_file = fopen (aux_info_file_name, "w"); | |
4475 | if (aux_info_file == 0) | |
fa6ef813 | 4476 | fatal_error ("can't open %s: %m", aux_info_file_name); |
f5e99456 | 4477 | } |
309a8875 | 4478 | |
f5e99456 | 4479 | if (! targetm.have_named_sections) |
4291d9c8 | 4480 | { |
f5e99456 NB |
4481 | if (flag_function_sections) |
4482 | { | |
4d6baafa | 4483 | warning ("-ffunction-sections not supported for this target"); |
f5e99456 NB |
4484 | flag_function_sections = 0; |
4485 | } | |
4486 | if (flag_data_sections) | |
4487 | { | |
4d6baafa | 4488 | warning ("-fdata-sections not supported for this target"); |
f5e99456 NB |
4489 | flag_data_sections = 0; |
4490 | } | |
4291d9c8 | 4491 | } |
f5e99456 | 4492 | |
8456b95a | 4493 | if (flag_function_sections && profile_flag) |
3d5cdd42 | 4494 | { |
4d6baafa | 4495 | warning ("-ffunction-sections disabled; it makes profiling impossible"); |
f5e99456 | 4496 | flag_function_sections = 0; |
3d5cdd42 | 4497 | } |
f5e99456 | 4498 | |
0dd0e980 JH |
4499 | #ifndef HAVE_prefetch |
4500 | if (flag_prefetch_loop_arrays) | |
4501 | { | |
4502 | warning ("-fprefetch-loop-arrays not supported for this target"); | |
4503 | flag_prefetch_loop_arrays = 0; | |
4504 | } | |
4505 | #else | |
4506 | if (flag_prefetch_loop_arrays && !HAVE_prefetch) | |
4507 | { | |
4508 | warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)"); | |
4509 | flag_prefetch_loop_arrays = 0; | |
4510 | } | |
4511 | #endif | |
4512 | ||
1398974c JJ |
4513 | /* This combination of options isn't handled for i386 targets and doesn't |
4514 | make much sense anyway, so don't allow it. */ | |
4515 | if (flag_prefetch_loop_arrays && optimize_size) | |
4516 | { | |
4517 | warning ("-fprefetch-loop-arrays is not supported with -Os"); | |
4518 | flag_prefetch_loop_arrays = 0; | |
4519 | } | |
4520 | ||
f5e99456 NB |
4521 | #ifndef OBJECT_FORMAT_ELF |
4522 | if (flag_function_sections && write_symbols != NO_DEBUG) | |
4d6baafa | 4523 | warning ("-ffunction-sections may affect debugging on some targets"); |
f5e99456 | 4524 | #endif |
52bfebf0 RS |
4525 | |
4526 | /* The presence of IEEE signaling NaNs, implies all math can trap. */ | |
4527 | if (flag_signaling_nans) | |
4528 | flag_trapping_math = 1; | |
4291d9c8 | 4529 | } |
ddc9542b | 4530 | |
c79043f3 | 4531 | /* Initialize the compiler back end. */ |
f5e99456 | 4532 | static void |
e25a75e6 | 4533 | backend_init (void) |
f5e99456 | 4534 | { |
b8eaca23 ZW |
4535 | init_adjust_machine_modes (); |
4536 | ||
f5e99456 NB |
4537 | init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL |
4538 | || debug_info_level == DINFO_LEVEL_VERBOSE | |
7a0c8d71 | 4539 | #ifdef VMS_DEBUGGING_INFO |
f9da5064 | 4540 | /* Enable line number info for traceback. */ |
7a0c8d71 DR |
4541 | || debug_info_level > DINFO_LEVEL_NONE |
4542 | #endif | |
4543 | || flag_test_coverage | |
4544 | || warn_notreached); | |
28420116 PB |
4545 | |
4546 | init_regs (); | |
6cde4876 | 4547 | init_fake_stack_mems (); |
f5e99456 | 4548 | init_alias_once (); |
f5e99456 NB |
4549 | init_loop (); |
4550 | init_reload (); | |
4551 | init_function_once (); | |
f5e99456 | 4552 | init_varasm_once (); |
f5e99456 NB |
4553 | |
4554 | /* The following initialization functions need to generate rtl, so | |
4555 | provide a dummy function context for them. */ | |
4556 | init_dummy_function_start (); | |
4557 | init_expmed (); | |
f5e99456 NB |
4558 | if (flag_caller_saves) |
4559 | init_caller_save (); | |
4560 | expand_dummy_function_end (); | |
4561 | } | |
ddc9542b | 4562 | |
0e9e1e0a | 4563 | /* Language-dependent initialization. Returns nonzero on success. */ |
22703ccc | 4564 | static int |
e25a75e6 | 4565 | lang_dependent_init (const char *name) |
4291d9c8 | 4566 | { |
f5e99456 NB |
4567 | if (dump_base_name == 0) |
4568 | dump_base_name = name ? name : "gccdump"; | |
26182e15 | 4569 | |
4bfec483 NB |
4570 | /* Other front-end initialization. */ |
4571 | if ((*lang_hooks.init) () == 0) | |
22703ccc | 4572 | return 0; |
4291d9c8 | 4573 | |
f5e99456 | 4574 | init_asm_output (name); |
3d5cdd42 | 4575 | |
f5e99456 NB |
4576 | /* These create various _DECL nodes, so need to be called after the |
4577 | front end is initialized. */ | |
4578 | init_eh (); | |
4579 | init_optabs (); | |
7ab0121e JW |
4580 | |
4581 | /* The following initialization functions need to generate rtl, so | |
4582 | provide a dummy function context for them. */ | |
4583 | init_dummy_function_start (); | |
1f8c3c5b | 4584 | init_expr_once (); |
7ab0121e | 4585 | expand_dummy_function_end (); |
3d5cdd42 | 4586 | |
f5e99456 NB |
4587 | /* If dbx symbol table desired, initialize writing it and output the |
4588 | predefined types. */ | |
4589 | timevar_push (TV_SYMOUT); | |
4291d9c8 | 4590 | |
f5e99456 NB |
4591 | #ifdef DWARF2_UNWIND_INFO |
4592 | if (dwarf2out_do_frame ()) | |
4593 | dwarf2out_frame_init (); | |
4594 | #endif | |
4291d9c8 | 4595 | |
f5e99456 NB |
4596 | /* Now we have the correct original filename, we can initialize |
4597 | debug output. */ | |
4598 | (*debug_hooks->init) (name); | |
4291d9c8 | 4599 | |
f5e99456 | 4600 | timevar_pop (TV_SYMOUT); |
22703ccc NB |
4601 | |
4602 | return 1; | |
4603 | } | |
ddc9542b | 4604 | |
22703ccc NB |
4605 | /* Clean up: close opened files, etc. */ |
4606 | ||
4607 | static void | |
e25a75e6 | 4608 | finalize (void) |
22703ccc NB |
4609 | { |
4610 | /* Close the dump files. */ | |
4611 | if (flag_gen_aux_info) | |
4612 | { | |
4613 | fclose (aux_info_file); | |
4614 | if (errorcount) | |
4615 | unlink (aux_info_file_name); | |
4616 | } | |
4617 | ||
4618 | /* Close non-debugging input and output files. Take special care to note | |
4619 | whether fclose returns an error, since the pages might still be on the | |
4620 | buffer chain while the file is open. */ | |
4621 | ||
4622 | if (asm_out_file) | |
4623 | { | |
4624 | if (ferror (asm_out_file) != 0) | |
fa6ef813 | 4625 | fatal_error ("error writing to %s: %m", asm_file_name); |
22703ccc | 4626 | if (fclose (asm_out_file) != 0) |
fa6ef813 | 4627 | fatal_error ("error closing %s: %m", asm_file_name); |
22703ccc NB |
4628 | } |
4629 | ||
4630 | /* Do whatever is necessary to finish printing the graphs. */ | |
4631 | if (graph_dump_format != no_graph) | |
4632 | { | |
4633 | int i; | |
4634 | ||
4635 | for (i = 0; i < (int) DFI_MAX; ++i) | |
4636 | if (dump_file[i].initialized && dump_file[i].graph_dump_p) | |
4637 | { | |
4638 | char seq[16]; | |
4639 | char *suffix; | |
4640 | ||
6baf9874 | 4641 | sprintf (seq, DUMPFILE_FORMAT, i); |
22703ccc NB |
4642 | suffix = concat (seq, dump_file[i].extension, NULL); |
4643 | finish_graph_dump_file (dump_base_name, suffix); | |
4644 | free (suffix); | |
4645 | } | |
4646 | } | |
4647 | ||
4648 | if (mem_report) | |
4649 | { | |
4650 | ggc_print_statistics (); | |
4651 | stringpool_statistics (); | |
4652 | dump_tree_statistics (); | |
4653 | } | |
4654 | ||
4655 | /* Free up memory for the benefit of leak detectors. */ | |
4656 | free_reg_info (); | |
4657 | ||
4658 | /* Language-specific end of compilation actions. */ | |
4659 | (*lang_hooks.finish) (); | |
f5e99456 | 4660 | } |
ddc9542b | 4661 | |
4d6baafa NB |
4662 | /* Initialize the compiler, and compile the input file. */ |
4663 | static void | |
e25a75e6 | 4664 | do_compile (void) |
f5e99456 | 4665 | { |
09b04f2d NB |
4666 | /* Initialize timing first. The C front ends read the main file in |
4667 | the post_options hook, and C++ does file timings. */ | |
4668 | if (time_report || !quiet_flag || flag_detailed_statistics) | |
4669 | timevar_init (); | |
a9915c78 RK |
4670 | timevar_start (TV_TOTAL); |
4671 | ||
09b04f2d NB |
4672 | process_options (); |
4673 | ||
4674 | /* Don't do any more if an error has already occurred. */ | |
4675 | if (!errorcount) | |
4676 | { | |
4677 | /* Set up the back-end if requested. */ | |
4678 | if (!no_backend) | |
4679 | backend_init (); | |
f5e99456 | 4680 | |
09b04f2d | 4681 | /* Language-dependent initialization. Returns true on success. */ |
d7b42618 | 4682 | if (lang_dependent_init (main_input_filename)) |
a194aa56 | 4683 | { |
a9189cc0 SB |
4684 | if (flag_unit_at_a_time) |
4685 | { | |
4686 | open_dump_file (DFI_cgraph, NULL); | |
4687 | cgraph_dump_file = rtl_dump_file; | |
4688 | rtl_dump_file = NULL; | |
4689 | } | |
4690 | ||
4691 | compile_file (); | |
4692 | ||
4693 | if (flag_unit_at_a_time) | |
4694 | { | |
4695 | rtl_dump_file = cgraph_dump_file; | |
4696 | cgraph_dump_file = NULL; | |
4697 | close_dump_file (DFI_cgraph, NULL, NULL_RTX); | |
4698 | } | |
a194aa56 JH |
4699 | } |
4700 | ||
09b04f2d NB |
4701 | finalize (); |
4702 | } | |
f5e99456 NB |
4703 | |
4704 | /* Stop timing and print the times. */ | |
4705 | timevar_stop (TV_TOTAL); | |
4706 | timevar_print (stderr); | |
4d6baafa | 4707 | } |
ddc9542b | 4708 | |
4d6baafa | 4709 | /* Entry point of cc1, cc1plus, jc1, f771, etc. |
4d6baafa NB |
4710 | Exit code is FATAL_EXIT_CODE if can't open files or if there were |
4711 | any errors, or SUCCESS_EXIT_CODE if compilation succeeded. | |
4712 | ||
4713 | It is not safe to call this function more than once. */ | |
4714 | ||
4715 | int | |
b86f6cd9 | 4716 | toplev_main (unsigned int argc, const char **argv) |
4d6baafa | 4717 | { |
b86f6cd9 NB |
4718 | save_argv = argv; |
4719 | ||
4d6baafa | 4720 | /* Initialization of GCC's environment, and diagnostics. */ |
9cabb1d8 | 4721 | general_init (argv[0]); |
4d6baafa NB |
4722 | |
4723 | /* Parse the options and do minimal processing; basically just | |
4724 | enough to default flags appropriately. */ | |
9756310a | 4725 | decode_options (argc, argv); |
4d6baafa | 4726 | |
c07e5477 NS |
4727 | randomize (); |
4728 | ||
4d6baafa | 4729 | /* Exit early if we can (e.g. -help). */ |
c79043f3 | 4730 | if (!exit_after_options) |
09b04f2d | 4731 | do_compile (); |
f5e99456 NB |
4732 | |
4733 | if (errorcount || sorrycount) | |
4734 | return (FATAL_EXIT_CODE); | |
4735 | ||
4736 | return (SUCCESS_EXIT_CODE); | |
4291d9c8 | 4737 | } |