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