]>
Commit | Line | Data |
---|---|---|
f6db1481 RH |
1 | /* Top level of GCC compilers (cc1, cc1plus, etc.) |
2 | Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | |
3 | 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 2, or (at your option) any later | |
10 | version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GCC; see the file COPYING. If not, write to the Free | |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | /* This is the top level of cc1/c++. | |
23 | It parses command args, opens files, invokes the various passes | |
24 | in the proper order, and counts the time used by each. | |
25 | Error messages and low-level interface to malloc also handled here. */ | |
26 | ||
27 | #include "config.h" | |
28 | #undef FLOAT /* This is for hpux. They should change hpux. */ | |
29 | #undef FFS /* Some systems define this in param.h. */ | |
30 | #include "system.h" | |
31 | #include "coretypes.h" | |
32 | #include "tm.h" | |
33 | #include <signal.h> | |
34 | ||
35 | #ifdef HAVE_SYS_RESOURCE_H | |
36 | # include <sys/resource.h> | |
37 | #endif | |
38 | ||
39 | #ifdef HAVE_SYS_TIMES_H | |
40 | # include <sys/times.h> | |
41 | #endif | |
42 | ||
43 | #include "line-map.h" | |
44 | #include "input.h" | |
45 | #include "tree.h" | |
46 | #include "rtl.h" | |
47 | #include "tm_p.h" | |
48 | #include "flags.h" | |
49 | #include "insn-attr.h" | |
50 | #include "insn-config.h" | |
51 | #include "insn-flags.h" | |
52 | #include "hard-reg-set.h" | |
53 | #include "recog.h" | |
54 | #include "output.h" | |
55 | #include "except.h" | |
56 | #include "function.h" | |
57 | #include "toplev.h" | |
58 | #include "expr.h" | |
59 | #include "basic-block.h" | |
60 | #include "intl.h" | |
61 | #include "ggc.h" | |
62 | #include "graph.h" | |
63 | #include "loop.h" | |
64 | #include "regs.h" | |
65 | #include "timevar.h" | |
66 | #include "diagnostic.h" | |
67 | #include "params.h" | |
68 | #include "reload.h" | |
69 | #include "dwarf2asm.h" | |
70 | #include "integrate.h" | |
71 | #include "real.h" | |
72 | #include "debug.h" | |
73 | #include "target.h" | |
74 | #include "langhooks.h" | |
75 | #include "cfglayout.h" | |
76 | #include "cfgloop.h" | |
77 | #include "hosthooks.h" | |
78 | #include "cgraph.h" | |
79 | #include "opts.h" | |
80 | #include "coverage.h" | |
81 | #include "value-prof.h" | |
82 | #include "alloc-pool.h" | |
83 | ||
84 | #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO) | |
85 | #include "dwarf2out.h" | |
86 | #endif | |
87 | ||
88 | #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) | |
89 | #include "dbxout.h" | |
90 | #endif | |
91 | ||
92 | #ifdef SDB_DEBUGGING_INFO | |
93 | #include "sdbout.h" | |
94 | #endif | |
95 | ||
96 | #ifdef XCOFF_DEBUGGING_INFO | |
97 | #include "xcoffout.h" /* Needed for external data | |
98 | declarations for e.g. AIX 4.x. */ | |
99 | #endif | |
100 | ||
101 | #ifndef HAVE_conditional_execution | |
102 | #define HAVE_conditional_execution 0 | |
103 | #endif | |
104 | ||
105 | /* Format to use to print dumpfile index value */ | |
106 | #ifndef DUMPFILE_FORMAT | |
107 | #define DUMPFILE_FORMAT ".%02d." | |
108 | #endif | |
109 | ||
110 | /* Describes a dump file. */ | |
111 | ||
112 | struct dump_file_info | |
113 | { | |
114 | /* The unique extension to apply, e.g. ".jump". */ | |
115 | const char *const extension; | |
116 | ||
117 | /* The -d<c> character that enables this dump file. */ | |
118 | char const debug_switch; | |
119 | ||
120 | /* True if there is a corresponding graph dump file. */ | |
121 | char const graph_dump_p; | |
122 | ||
123 | /* True if the user selected this dump. */ | |
124 | char enabled; | |
125 | ||
126 | /* True if the files have been initialized (ie truncated). */ | |
127 | char initialized; | |
128 | }; | |
129 | ||
130 | /* Enumerate the extant dump files. */ | |
131 | ||
132 | enum dump_file_index | |
133 | { | |
134 | DFI_cgraph, | |
135 | DFI_rtl, | |
136 | DFI_sibling, | |
137 | DFI_eh, | |
138 | DFI_jump, | |
139 | DFI_null, | |
140 | DFI_cse, | |
141 | DFI_addressof, | |
142 | DFI_gcse, | |
143 | DFI_loop, | |
144 | DFI_bypass, | |
145 | DFI_cfg, | |
146 | DFI_bp, | |
147 | DFI_vpt, | |
148 | DFI_ce1, | |
149 | DFI_tracer, | |
150 | DFI_loop2, | |
151 | DFI_web, | |
152 | DFI_cse2, | |
153 | DFI_life, | |
154 | DFI_combine, | |
155 | DFI_ce2, | |
156 | DFI_regmove, | |
157 | DFI_sched, | |
158 | DFI_lreg, | |
159 | DFI_greg, | |
160 | DFI_postreload, | |
f9957958 | 161 | DFI_gcse2, |
f6db1481 RH |
162 | DFI_flow2, |
163 | DFI_peephole2, | |
164 | DFI_ce3, | |
165 | DFI_rnreg, | |
166 | DFI_bbro, | |
167 | DFI_branch_target_load, | |
168 | DFI_sched2, | |
169 | DFI_stack, | |
170 | DFI_vartrack, | |
171 | DFI_mach, | |
172 | DFI_dbr, | |
173 | DFI_MAX | |
174 | }; | |
175 | ||
176 | /* Describes all the dump files. Should be kept in order of the | |
177 | pass and in sync with dump_file_index above. | |
178 | ||
179 | Remaining -d letters: | |
180 | ||
181 | " e m q " | |
f9957958 | 182 | " K O Q WXY " |
f6db1481 RH |
183 | */ |
184 | ||
185 | static struct dump_file_info dump_file_tbl[DFI_MAX] = | |
186 | { | |
187 | { "cgraph", 'U', 0, 0, 0 }, | |
188 | { "rtl", 'r', 0, 0, 0 }, | |
189 | { "sibling", 'i', 0, 0, 0 }, | |
190 | { "eh", 'h', 0, 0, 0 }, | |
191 | { "jump", 'j', 0, 0, 0 }, | |
192 | { "null", 'u', 0, 0, 0 }, | |
193 | { "cse", 's', 0, 0, 0 }, | |
194 | { "addressof", 'F', 0, 0, 0 }, | |
195 | { "gcse", 'G', 1, 0, 0 }, | |
196 | { "loop", 'L', 1, 0, 0 }, | |
197 | { "bypass", 'G', 1, 0, 0 }, /* Yes, duplicate enable switch. */ | |
198 | { "cfg", 'f', 1, 0, 0 }, | |
199 | { "bp", 'b', 1, 0, 0 }, | |
200 | { "vpt", 'V', 1, 0, 0 }, | |
201 | { "ce1", 'C', 1, 0, 0 }, | |
202 | { "tracer", 'T', 1, 0, 0 }, | |
203 | { "loop2", 'L', 1, 0, 0 }, | |
204 | { "web", 'Z', 0, 0, 0 }, | |
205 | { "cse2", 't', 1, 0, 0 }, | |
206 | { "life", 'f', 1, 0, 0 }, /* Yes, duplicate enable switch. */ | |
207 | { "combine", 'c', 1, 0, 0 }, | |
208 | { "ce2", 'C', 1, 0, 0 }, | |
209 | { "regmove", 'N', 1, 0, 0 }, | |
210 | { "sched", 'S', 1, 0, 0 }, | |
211 | { "lreg", 'l', 1, 0, 0 }, | |
212 | { "greg", 'g', 1, 0, 0 }, | |
213 | { "postreload", 'o', 1, 0, 0 }, | |
f9957958 | 214 | { "gcse2", 'J', 0, 0, 0 }, |
f6db1481 RH |
215 | { "flow2", 'w', 1, 0, 0 }, |
216 | { "peephole2", 'z', 1, 0, 0 }, | |
217 | { "ce3", 'E', 1, 0, 0 }, | |
218 | { "rnreg", 'n', 1, 0, 0 }, | |
219 | { "bbro", 'B', 1, 0, 0 }, | |
220 | { "btl", 'd', 1, 0, 0 }, /* Yes, duplicate enable switch. */ | |
221 | { "sched2", 'R', 1, 0, 0 }, | |
222 | { "stack", 'k', 1, 0, 0 }, | |
223 | { "vartrack", 'V', 1, 0, 0 }, /* Yes, duplicate enable switch. */ | |
224 | { "mach", 'M', 1, 0, 0 }, | |
225 | { "dbr", 'd', 0, 0, 0 }, | |
226 | }; | |
227 | ||
228 | /* Routine to open a dump file. Return true if the dump file is enabled. */ | |
229 | ||
230 | static int | |
231 | open_dump_file (enum dump_file_index index, tree decl) | |
232 | { | |
233 | char *dump_name; | |
234 | const char *open_arg; | |
235 | char seq[16]; | |
236 | ||
237 | if (! dump_file_tbl[index].enabled) | |
238 | return 0; | |
239 | ||
240 | timevar_push (TV_DUMP); | |
241 | if (dump_file != NULL) | |
242 | fclose (dump_file); | |
243 | ||
244 | sprintf (seq, DUMPFILE_FORMAT, index); | |
245 | ||
246 | if (! dump_file_tbl[index].initialized) | |
247 | { | |
248 | /* If we've not initialized the files, do so now. */ | |
249 | if (graph_dump_format != no_graph | |
250 | && dump_file_tbl[index].graph_dump_p) | |
251 | { | |
252 | dump_name = concat (seq, dump_file_tbl[index].extension, NULL); | |
253 | clean_graph_dump_file (dump_base_name, dump_name); | |
254 | free (dump_name); | |
255 | } | |
256 | dump_file_tbl[index].initialized = 1; | |
257 | open_arg = "w"; | |
258 | } | |
259 | else | |
260 | open_arg = "a"; | |
261 | ||
262 | dump_name = concat (dump_base_name, seq, | |
263 | dump_file_tbl[index].extension, NULL); | |
264 | ||
265 | dump_file = fopen (dump_name, open_arg); | |
266 | if (dump_file == NULL) | |
267 | fatal_error ("can't open %s: %m", dump_name); | |
268 | ||
269 | free (dump_name); | |
270 | ||
271 | if (decl) | |
272 | fprintf (dump_file, "\n;; Function %s%s\n\n", | |
ae2bcd98 | 273 | lang_hooks.decl_printable_name (decl, 2), |
f6db1481 RH |
274 | cfun->function_frequency == FUNCTION_FREQUENCY_HOT |
275 | ? " (hot)" | |
276 | : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED | |
277 | ? " (unlikely executed)" | |
278 | : ""); | |
279 | ||
280 | timevar_pop (TV_DUMP); | |
281 | return 1; | |
282 | } | |
283 | ||
284 | /* Routine to close a dump file. */ | |
285 | ||
286 | static void | |
287 | close_dump_file (enum dump_file_index index, | |
288 | void (*func) (FILE *, rtx), | |
289 | rtx insns) | |
290 | { | |
291 | if (! dump_file) | |
292 | return; | |
293 | ||
294 | timevar_push (TV_DUMP); | |
295 | if (insns | |
296 | && graph_dump_format != no_graph | |
297 | && dump_file_tbl[index].graph_dump_p) | |
298 | { | |
299 | char seq[16]; | |
300 | char *suffix; | |
301 | ||
302 | sprintf (seq, DUMPFILE_FORMAT, index); | |
303 | suffix = concat (seq, dump_file_tbl[index].extension, NULL); | |
304 | print_rtl_graph_with_bb (dump_base_name, suffix, insns); | |
305 | free (suffix); | |
306 | } | |
307 | ||
308 | if (func && insns) | |
309 | func (dump_file, insns); | |
310 | ||
311 | fflush (dump_file); | |
312 | fclose (dump_file); | |
313 | ||
314 | dump_file = NULL; | |
315 | timevar_pop (TV_DUMP); | |
316 | } | |
317 | ||
318 | /* This is called from various places for FUNCTION_DECL, VAR_DECL, | |
319 | and TYPE_DECL nodes. | |
320 | ||
321 | This does nothing for local (non-static) variables, unless the | |
322 | variable is a register variable with an ASMSPEC. In that case, or | |
323 | if the variable is not an automatic, it sets up the RTL and | |
324 | outputs any assembler code (label definition, storage allocation | |
325 | and initialization). | |
326 | ||
327 | DECL is the declaration. If ASMSPEC is nonzero, it specifies | |
328 | the assembler symbol name to be used. TOP_LEVEL is nonzero | |
329 | if this declaration is not within a function. */ | |
330 | ||
331 | void | |
332 | rest_of_decl_compilation (tree decl, | |
333 | const char *asmspec, | |
334 | int top_level, | |
335 | int at_end) | |
336 | { | |
337 | /* We deferred calling assemble_alias so that we could collect | |
338 | other attributes such as visibility. Emit the alias now. */ | |
339 | { | |
340 | tree alias; | |
341 | alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)); | |
342 | if (alias) | |
343 | { | |
344 | alias = TREE_VALUE (TREE_VALUE (alias)); | |
345 | alias = get_identifier (TREE_STRING_POINTER (alias)); | |
346 | assemble_alias (decl, alias); | |
347 | } | |
348 | } | |
349 | ||
350 | /* Forward declarations for nested functions are not "external", | |
351 | but we need to treat them as if they were. */ | |
352 | if (TREE_STATIC (decl) || DECL_EXTERNAL (decl) | |
353 | || TREE_CODE (decl) == FUNCTION_DECL) | |
354 | { | |
355 | timevar_push (TV_VARCONST); | |
356 | ||
357 | if (asmspec) | |
358 | make_decl_rtl (decl, asmspec); | |
359 | ||
360 | /* Don't output anything when a tentative file-scope definition | |
361 | is seen. But at end of compilation, do output code for them. | |
362 | ||
363 | We do output all variables when unit-at-a-time is active and rely on | |
364 | callgraph code to defer them except for forward declarations | |
365 | (see gcc.c-torture/compile/920624-1.c) */ | |
366 | if ((at_end | |
367 | || !DECL_DEFER_OUTPUT (decl) | |
368 | || (flag_unit_at_a_time && DECL_INITIAL (decl))) | |
369 | && !DECL_EXTERNAL (decl)) | |
370 | { | |
371 | if (flag_unit_at_a_time && !cgraph_global_info_ready | |
372 | && TREE_CODE (decl) != FUNCTION_DECL && top_level) | |
373 | cgraph_varpool_finalize_decl (decl); | |
374 | else | |
375 | assemble_variable (decl, top_level, at_end, 0); | |
376 | } | |
377 | ||
378 | #ifdef ASM_FINISH_DECLARE_OBJECT | |
379 | if (decl == last_assemble_variable_decl) | |
380 | { | |
381 | ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl, | |
382 | top_level, at_end); | |
383 | } | |
384 | #endif | |
385 | ||
386 | timevar_pop (TV_VARCONST); | |
387 | } | |
388 | else if (DECL_REGISTER (decl) && asmspec != 0) | |
389 | { | |
390 | if (decode_reg_name (asmspec) >= 0) | |
391 | { | |
392 | SET_DECL_RTL (decl, NULL_RTX); | |
393 | make_decl_rtl (decl, asmspec); | |
394 | } | |
395 | else | |
396 | { | |
6de9cd9a DN |
397 | error ("%Hinvalid register name `%s' for register variable", |
398 | &DECL_SOURCE_LOCATION (decl), asmspec); | |
f6db1481 RH |
399 | DECL_REGISTER (decl) = 0; |
400 | if (!top_level) | |
401 | expand_decl (decl); | |
402 | } | |
403 | } | |
404 | else if (TREE_CODE (decl) == TYPE_DECL) | |
405 | { | |
406 | timevar_push (TV_SYMOUT); | |
407 | debug_hooks->type_decl (decl, !top_level); | |
408 | timevar_pop (TV_SYMOUT); | |
409 | } | |
410 | } | |
411 | ||
412 | /* Called after finishing a record, union or enumeral type. */ | |
413 | ||
414 | void | |
415 | rest_of_type_compilation (tree type, int toplev) | |
416 | { | |
417 | /* Avoid confusing the debug information machinery when there are | |
418 | errors. */ | |
419 | if (errorcount != 0 || sorrycount != 0) | |
420 | return; | |
421 | ||
422 | timevar_push (TV_SYMOUT); | |
423 | debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev); | |
424 | timevar_pop (TV_SYMOUT); | |
425 | } | |
426 | ||
427 | /* Turn the RTL into assembly. */ | |
428 | static void | |
429 | rest_of_handle_final (tree decl, rtx insns) | |
430 | { | |
431 | timevar_push (TV_FINAL); | |
432 | { | |
433 | rtx x; | |
434 | const char *fnname; | |
435 | ||
436 | /* Get the function's name, as described by its RTL. This may be | |
437 | different from the DECL_NAME name used in the source file. */ | |
438 | ||
439 | x = DECL_RTL (decl); | |
440 | if (GET_CODE (x) != MEM) | |
441 | abort (); | |
442 | x = XEXP (x, 0); | |
443 | if (GET_CODE (x) != SYMBOL_REF) | |
444 | abort (); | |
445 | fnname = XSTR (x, 0); | |
446 | ||
447 | assemble_start_function (decl, fnname); | |
448 | final_start_function (insns, asm_out_file, optimize); | |
449 | final (insns, asm_out_file, optimize, 0); | |
450 | final_end_function (); | |
451 | ||
452 | #ifdef IA64_UNWIND_INFO | |
453 | /* ??? The IA-64 ".handlerdata" directive must be issued before | |
454 | the ".endp" directive that closes the procedure descriptor. */ | |
455 | output_function_exception_table (); | |
456 | #endif | |
457 | ||
458 | assemble_end_function (decl, fnname); | |
459 | ||
460 | #ifndef IA64_UNWIND_INFO | |
461 | /* Otherwise, it feels unclean to switch sections in the middle. */ | |
462 | output_function_exception_table (); | |
463 | #endif | |
464 | ||
465 | if (! quiet_flag) | |
466 | fflush (asm_out_file); | |
467 | ||
468 | /* Release all memory allocated by flow. */ | |
bb8a619e | 469 | free_basic_block_vars (); |
f6db1481 RH |
470 | |
471 | /* Release all memory held by regsets now. */ | |
472 | regset_release_memory (); | |
473 | } | |
474 | timevar_pop (TV_FINAL); | |
475 | ||
476 | ggc_collect (); | |
477 | } | |
478 | ||
479 | #ifdef DELAY_SLOTS | |
480 | /* Run delay slot optimization. */ | |
481 | static void | |
482 | rest_of_handle_delay_slots (tree decl, rtx insns) | |
483 | { | |
484 | timevar_push (TV_DBR_SCHED); | |
485 | open_dump_file (DFI_dbr, decl); | |
486 | ||
487 | dbr_schedule (insns, dump_file); | |
488 | ||
489 | close_dump_file (DFI_dbr, print_rtl, insns); | |
490 | timevar_pop (TV_DBR_SCHED); | |
491 | ||
492 | ggc_collect (); | |
493 | } | |
494 | #endif | |
495 | ||
496 | #ifdef STACK_REGS | |
497 | /* Convert register usage from flat register file usage to a stack | |
498 | register file. */ | |
499 | static void | |
500 | rest_of_handle_stack_regs (tree decl, rtx insns) | |
501 | { | |
502 | #if defined (HAVE_ATTR_length) | |
503 | /* If flow2 creates new instructions which need splitting | |
504 | and scheduling after reload is not done, they might not be | |
505 | split until final which doesn't allow splitting | |
506 | if HAVE_ATTR_length. */ | |
507 | #ifdef INSN_SCHEDULING | |
508 | if (optimize && !flag_schedule_insns_after_reload) | |
509 | #else | |
510 | if (optimize) | |
511 | #endif | |
512 | { | |
513 | timevar_push (TV_SHORTEN_BRANCH); | |
514 | split_all_insns (1); | |
515 | timevar_pop (TV_SHORTEN_BRANCH); | |
516 | } | |
517 | #endif | |
518 | ||
519 | timevar_push (TV_REG_STACK); | |
520 | open_dump_file (DFI_stack, decl); | |
521 | ||
522 | if (reg_to_stack (insns, dump_file) && optimize) | |
523 | { | |
524 | if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK | |
525 | | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0)) | |
750054a2 | 526 | && (flag_reorder_blocks || flag_reorder_blocks_and_partition)) |
f6db1481 RH |
527 | { |
528 | reorder_basic_blocks (); | |
529 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK); | |
530 | } | |
531 | } | |
532 | ||
533 | close_dump_file (DFI_stack, print_rtl_with_bb, insns); | |
534 | timevar_pop (TV_REG_STACK); | |
535 | ||
536 | ggc_collect (); | |
537 | } | |
538 | #endif | |
539 | ||
540 | /* Track the variables, ie. compute where the variable is stored at each position in function. */ | |
541 | static void | |
542 | rest_of_handle_variable_tracking (tree decl, rtx insns) | |
543 | { | |
544 | timevar_push (TV_VAR_TRACKING); | |
545 | open_dump_file (DFI_vartrack, decl); | |
546 | ||
547 | variable_tracking_main (); | |
548 | ||
549 | close_dump_file (DFI_vartrack, print_rtl_with_bb, insns); | |
550 | timevar_pop (TV_VAR_TRACKING); | |
551 | } | |
552 | ||
553 | /* Machine independent reorg pass. */ | |
554 | static void | |
555 | rest_of_handle_machine_reorg (tree decl, rtx insns) | |
556 | { | |
557 | timevar_push (TV_MACH_DEP); | |
558 | open_dump_file (DFI_mach, decl); | |
559 | ||
5fd9b178 | 560 | targetm.machine_dependent_reorg (); |
f6db1481 RH |
561 | |
562 | close_dump_file (DFI_mach, print_rtl, insns); | |
563 | timevar_pop (TV_MACH_DEP); | |
564 | ||
565 | ggc_collect (); | |
566 | } | |
567 | ||
568 | ||
569 | /* Run new register allocator. Return TRUE if we must exit | |
570 | rest_of_compilation upon return. */ | |
571 | static bool | |
572 | rest_of_handle_new_regalloc (tree decl, rtx insns) | |
573 | { | |
574 | int failure; | |
575 | ||
576 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
577 | reg_alloc (); | |
578 | ||
579 | timevar_pop (TV_LOCAL_ALLOC); | |
580 | if (dump_file_tbl[DFI_lreg].enabled) | |
581 | { | |
582 | timevar_push (TV_DUMP); | |
583 | ||
584 | close_dump_file (DFI_lreg, NULL, NULL); | |
585 | timevar_pop (TV_DUMP); | |
586 | } | |
587 | ||
588 | /* XXX clean up the whole mess to bring live info in shape again. */ | |
589 | timevar_push (TV_GLOBAL_ALLOC); | |
590 | open_dump_file (DFI_greg, decl); | |
591 | ||
592 | build_insn_chain (insns); | |
593 | failure = reload (insns, 0); | |
594 | ||
595 | timevar_pop (TV_GLOBAL_ALLOC); | |
596 | ||
597 | if (dump_file_tbl[DFI_greg].enabled) | |
598 | { | |
599 | timevar_push (TV_DUMP); | |
600 | ||
601 | dump_global_regs (dump_file); | |
602 | ||
603 | close_dump_file (DFI_greg, print_rtl_with_bb, insns); | |
604 | timevar_pop (TV_DUMP); | |
605 | } | |
606 | ||
607 | if (failure) | |
608 | return true; | |
609 | ||
610 | reload_completed = 1; | |
611 | ||
612 | return false; | |
613 | } | |
614 | ||
615 | /* Run old register allocator. Return TRUE if we must exit | |
616 | rest_of_compilation upon return. */ | |
617 | static bool | |
618 | rest_of_handle_old_regalloc (tree decl, rtx insns) | |
619 | { | |
620 | int failure; | |
621 | int rebuild_notes; | |
622 | ||
623 | /* Allocate the reg_renumber array. */ | |
624 | allocate_reg_info (max_regno, FALSE, TRUE); | |
625 | ||
626 | /* And the reg_equiv_memory_loc array. */ | |
627 | reg_equiv_memory_loc = xcalloc (max_regno, sizeof (rtx)); | |
628 | ||
629 | allocate_initial_values (reg_equiv_memory_loc); | |
630 | ||
631 | regclass (insns, max_reg_num (), dump_file); | |
632 | rebuild_notes = local_alloc (); | |
633 | ||
634 | timevar_pop (TV_LOCAL_ALLOC); | |
635 | ||
636 | /* Local allocation may have turned an indirect jump into a direct | |
637 | jump. If so, we must rebuild the JUMP_LABEL fields of jumping | |
638 | instructions. */ | |
639 | if (rebuild_notes) | |
640 | { | |
641 | timevar_push (TV_JUMP); | |
642 | ||
643 | rebuild_jump_labels (insns); | |
644 | purge_all_dead_edges (0); | |
645 | ||
646 | timevar_pop (TV_JUMP); | |
647 | } | |
648 | ||
649 | if (dump_file_tbl[DFI_lreg].enabled) | |
650 | { | |
651 | timevar_push (TV_DUMP); | |
652 | ||
653 | dump_flow_info (dump_file); | |
654 | dump_local_alloc (dump_file); | |
655 | ||
656 | close_dump_file (DFI_lreg, print_rtl_with_bb, insns); | |
657 | timevar_pop (TV_DUMP); | |
658 | } | |
659 | ||
660 | ggc_collect (); | |
661 | ||
662 | timevar_push (TV_GLOBAL_ALLOC); | |
663 | open_dump_file (DFI_greg, decl); | |
664 | ||
665 | /* If optimizing, allocate remaining pseudo-regs. Do the reload | |
666 | pass fixing up any insns that are invalid. */ | |
667 | ||
668 | if (optimize) | |
669 | failure = global_alloc (dump_file); | |
670 | else | |
671 | { | |
672 | build_insn_chain (insns); | |
673 | failure = reload (insns, 0); | |
674 | } | |
675 | ||
676 | timevar_pop (TV_GLOBAL_ALLOC); | |
677 | ||
678 | if (dump_file_tbl[DFI_greg].enabled) | |
679 | { | |
680 | timevar_push (TV_DUMP); | |
681 | ||
682 | dump_global_regs (dump_file); | |
683 | ||
684 | close_dump_file (DFI_greg, print_rtl_with_bb, insns); | |
685 | timevar_pop (TV_DUMP); | |
686 | } | |
687 | ||
688 | return failure; | |
689 | } | |
690 | ||
691 | /* Run the regrename and cprop passes. */ | |
692 | static void | |
693 | rest_of_handle_regrename (tree decl, rtx insns) | |
694 | { | |
695 | timevar_push (TV_RENAME_REGISTERS); | |
696 | open_dump_file (DFI_rnreg, decl); | |
697 | ||
698 | if (flag_rename_registers) | |
699 | regrename_optimize (); | |
700 | if (flag_cprop_registers) | |
701 | copyprop_hardreg_forward (); | |
702 | ||
703 | close_dump_file (DFI_rnreg, print_rtl_with_bb, insns); | |
704 | timevar_pop (TV_RENAME_REGISTERS); | |
705 | } | |
706 | ||
707 | /* Reorder basic blocks. */ | |
708 | static void | |
709 | rest_of_handle_reorder_blocks (tree decl, rtx insns) | |
710 | { | |
711 | bool changed; | |
712 | open_dump_file (DFI_bbro, decl); | |
713 | ||
714 | /* Last attempt to optimize CFG, as scheduling, peepholing and insn | |
715 | splitting possibly introduced more crossjumping opportunities. */ | |
716 | changed = cleanup_cfg (CLEANUP_EXPENSIVE | |
717 | | (!HAVE_conditional_execution | |
718 | ? CLEANUP_UPDATE_LIFE : 0)); | |
719 | ||
720 | if (flag_sched2_use_traces && flag_schedule_insns_after_reload) | |
721 | tracer (); | |
750054a2 | 722 | if (flag_reorder_blocks || flag_reorder_blocks_and_partition) |
f6db1481 | 723 | reorder_basic_blocks (); |
750054a2 | 724 | if (flag_reorder_blocks || flag_reorder_blocks_and_partition |
f6db1481 RH |
725 | || (flag_sched2_use_traces && flag_schedule_insns_after_reload)) |
726 | changed |= cleanup_cfg (CLEANUP_EXPENSIVE | |
727 | | (!HAVE_conditional_execution | |
728 | ? CLEANUP_UPDATE_LIFE : 0)); | |
729 | ||
730 | /* On conditional execution targets we can not update the life cheaply, so | |
731 | we deffer the updating to after both cleanups. This may lose some cases | |
732 | but should not be terribly bad. */ | |
733 | if (changed && HAVE_conditional_execution) | |
734 | update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES, | |
735 | PROP_DEATH_NOTES); | |
736 | close_dump_file (DFI_bbro, print_rtl_with_bb, insns); | |
737 | } | |
738 | ||
739 | #ifdef INSN_SCHEDULING | |
740 | /* Run instruction scheduler. */ | |
741 | static void | |
742 | rest_of_handle_sched (tree decl, rtx insns) | |
743 | { | |
744 | timevar_push (TV_SCHED); | |
745 | ||
746 | /* Print function header into sched dump now | |
747 | because doing the sched analysis makes some of the dump. */ | |
748 | if (optimize > 0 && flag_schedule_insns) | |
749 | { | |
750 | open_dump_file (DFI_sched, decl); | |
751 | ||
752 | /* Do control and data sched analysis, | |
753 | and write some of the results to dump file. */ | |
754 | ||
755 | schedule_insns (dump_file); | |
756 | ||
757 | close_dump_file (DFI_sched, print_rtl_with_bb, insns); | |
758 | } | |
759 | timevar_pop (TV_SCHED); | |
760 | ||
761 | ggc_collect (); | |
762 | } | |
763 | ||
764 | /* Run second scheduling pass after reload. */ | |
765 | static void | |
766 | rest_of_handle_sched2 (tree decl, rtx insns) | |
767 | { | |
768 | timevar_push (TV_SCHED2); | |
769 | open_dump_file (DFI_sched2, decl); | |
770 | ||
771 | /* Do control and data sched analysis again, | |
772 | and write some more of the results to dump file. */ | |
773 | ||
774 | split_all_insns (1); | |
775 | ||
776 | if (flag_sched2_use_superblocks || flag_sched2_use_traces) | |
777 | { | |
778 | schedule_ebbs (dump_file); | |
779 | /* No liveness updating code yet, but it should be easy to do. | |
4ee31f1e | 780 | reg-stack recomputes the liveness when needed for now. */ |
f6db1481 RH |
781 | count_or_remove_death_notes (NULL, 1); |
782 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
783 | } | |
784 | else | |
785 | schedule_insns (dump_file); | |
786 | ||
787 | close_dump_file (DFI_sched2, print_rtl_with_bb, insns); | |
788 | timevar_pop (TV_SCHED2); | |
789 | ||
790 | ggc_collect (); | |
791 | } | |
792 | #endif | |
793 | ||
f9957958 MH |
794 | static void |
795 | rest_of_handle_gcse2 (tree decl, rtx insns) | |
796 | { | |
797 | open_dump_file (DFI_gcse2, decl); | |
798 | ||
799 | gcse_after_reload_main (insns, dump_file); | |
800 | rebuild_jump_labels (insns); | |
801 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
802 | close_dump_file (DFI_gcse2, print_rtl_with_bb, insns); | |
803 | ||
804 | ggc_collect (); | |
805 | ||
806 | #ifdef ENABLE_CHECKING | |
807 | verify_flow_info (); | |
808 | #endif | |
809 | } | |
810 | ||
f6db1481 RH |
811 | /* Register allocation pre-pass, to reduce number of moves necessary |
812 | for two-address machines. */ | |
813 | static void | |
814 | rest_of_handle_regmove (tree decl, rtx insns) | |
815 | { | |
816 | timevar_push (TV_REGMOVE); | |
817 | open_dump_file (DFI_regmove, decl); | |
818 | ||
819 | regmove_optimize (insns, max_reg_num (), dump_file); | |
820 | ||
821 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE); | |
822 | close_dump_file (DFI_regmove, print_rtl_with_bb, insns); | |
823 | timevar_pop (TV_REGMOVE); | |
824 | ||
825 | ggc_collect (); | |
826 | } | |
827 | ||
828 | /* Run tracer. */ | |
829 | static void | |
830 | rest_of_handle_tracer (tree decl, rtx insns) | |
831 | { | |
832 | open_dump_file (DFI_tracer, decl); | |
833 | if (dump_file) | |
834 | dump_flow_info (dump_file); | |
835 | tracer (); | |
836 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
837 | reg_scan (insns, max_reg_num (), 0); | |
838 | close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ()); | |
839 | } | |
840 | ||
841 | /* If-conversion and CFG cleanup. */ | |
842 | static void | |
843 | rest_of_handle_if_conversion (tree decl, rtx insns) | |
844 | { | |
845 | open_dump_file (DFI_ce1, decl); | |
846 | if (flag_if_conversion) | |
847 | { | |
848 | timevar_push (TV_IFCVT); | |
849 | if (dump_file) | |
850 | dump_flow_info (dump_file); | |
851 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
852 | reg_scan (insns, max_reg_num (), 0); | |
853 | if_convert (0); | |
854 | timevar_pop (TV_IFCVT); | |
855 | } | |
856 | timevar_push (TV_JUMP); | |
857 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
858 | reg_scan (insns, max_reg_num (), 0); | |
859 | timevar_pop (TV_JUMP); | |
860 | close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ()); | |
861 | } | |
862 | ||
863 | /* Rerun if-conversion, as combine may have simplified things enough | |
864 | to now meet sequence length restrictions. */ | |
865 | static void | |
866 | rest_of_handle_if_after_combine (tree decl, rtx insns) | |
867 | { | |
868 | timevar_push (TV_IFCVT); | |
869 | open_dump_file (DFI_ce2, decl); | |
870 | ||
871 | no_new_pseudos = 0; | |
872 | if_convert (1); | |
873 | no_new_pseudos = 1; | |
874 | ||
875 | close_dump_file (DFI_ce2, print_rtl_with_bb, insns); | |
876 | timevar_pop (TV_IFCVT); | |
877 | } | |
878 | ||
879 | static void | |
880 | rest_of_handle_web (tree decl, rtx insns) | |
881 | { | |
882 | open_dump_file (DFI_web, decl); | |
883 | timevar_push (TV_WEB); | |
884 | web_main (); | |
885 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
886 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
887 | ||
888 | timevar_pop (TV_WEB); | |
889 | close_dump_file (DFI_web, print_rtl_with_bb, insns); | |
890 | reg_scan (get_insns (), max_reg_num (), 0); | |
891 | } | |
892 | ||
893 | /* Do branch profiling and static profile estimation passes. */ | |
894 | static void | |
895 | rest_of_handle_branch_prob (tree decl, rtx insns) | |
896 | { | |
897 | struct loops loops; | |
898 | ||
899 | timevar_push (TV_BRANCH_PROB); | |
900 | open_dump_file (DFI_bp, decl); | |
901 | ||
902 | if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities) | |
903 | branch_prob (); | |
904 | ||
905 | /* Discover and record the loop depth at the head of each basic | |
906 | block. The loop infrastructure does the real job for us. */ | |
907 | flow_loops_find (&loops, LOOP_TREE); | |
908 | ||
909 | if (dump_file) | |
910 | flow_loops_dump (&loops, dump_file, NULL, 0); | |
911 | ||
912 | /* Estimate using heuristics if no profiling info is available. */ | |
913 | if (flag_guess_branch_prob) | |
914 | estimate_probability (&loops); | |
915 | ||
916 | flow_loops_free (&loops); | |
917 | free_dominance_info (CDI_DOMINATORS); | |
918 | close_dump_file (DFI_bp, print_rtl_with_bb, insns); | |
919 | timevar_pop (TV_BRANCH_PROB); | |
920 | } | |
921 | ||
922 | /* Do optimizations based on expression value profiles. */ | |
923 | static void | |
924 | rest_of_handle_value_profile_transformations (tree decl, rtx insns) | |
925 | { | |
926 | open_dump_file (DFI_vpt, decl); | |
927 | timevar_push (TV_VPT); | |
928 | ||
929 | if (value_profile_transformations ()) | |
930 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
931 | ||
932 | timevar_pop (TV_VPT); | |
933 | close_dump_file (DFI_vpt, print_rtl_with_bb, insns); | |
934 | } | |
935 | ||
936 | /* Do control and data flow analysis; write some of the results to the | |
937 | dump file. */ | |
938 | static void | |
939 | rest_of_handle_cfg (tree decl, rtx insns) | |
940 | { | |
941 | open_dump_file (DFI_cfg, decl); | |
942 | if (dump_file) | |
943 | dump_flow_info (dump_file); | |
944 | if (optimize) | |
945 | cleanup_cfg (CLEANUP_EXPENSIVE | |
946 | | (flag_thread_jumps ? CLEANUP_THREADING : 0)); | |
947 | ||
948 | /* It may make more sense to mark constant functions after dead code is | |
949 | eliminated by life_analysis, but we need to do it early, as -fprofile-arcs | |
950 | may insert code making function non-constant, but we still must consider | |
951 | it as constant, otherwise -fbranch-probabilities will not read data back. | |
952 | ||
953 | life_analysis rarely eliminates modification of external memory. | |
954 | */ | |
955 | if (optimize) | |
956 | { | |
957 | /* Alias analysis depends on this information and mark_constant_function | |
958 | depends on alias analysis. */ | |
959 | reg_scan (insns, max_reg_num (), 1); | |
960 | mark_constant_function (); | |
961 | } | |
962 | ||
963 | close_dump_file (DFI_cfg, print_rtl_with_bb, insns); | |
964 | } | |
965 | ||
966 | /* Purge addressofs. */ | |
967 | static void | |
968 | rest_of_handle_addressof (tree decl, rtx insns) | |
969 | { | |
970 | open_dump_file (DFI_addressof, decl); | |
971 | ||
972 | purge_addressof (insns); | |
973 | if (optimize && purge_all_dead_edges (0)) | |
974 | delete_unreachable_blocks (); | |
975 | reg_scan (insns, max_reg_num (), 1); | |
976 | ||
977 | close_dump_file (DFI_addressof, print_rtl, insns); | |
978 | } | |
979 | ||
f6db1481 RH |
980 | /* Perform jump bypassing and control flow optimizations. */ |
981 | static void | |
982 | rest_of_handle_jump_bypass (tree decl, rtx insns) | |
983 | { | |
984 | timevar_push (TV_BYPASS); | |
985 | open_dump_file (DFI_bypass, decl); | |
986 | ||
987 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
988 | reg_scan (insns, max_reg_num (), 1); | |
989 | ||
990 | if (bypass_jumps (dump_file)) | |
991 | { | |
992 | rebuild_jump_labels (insns); | |
993 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
994 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
995 | } | |
996 | ||
997 | close_dump_file (DFI_bypass, print_rtl_with_bb, insns); | |
998 | timevar_pop (TV_BYPASS); | |
999 | ||
1000 | ggc_collect (); | |
1001 | ||
1002 | #ifdef ENABLE_CHECKING | |
1003 | verify_flow_info (); | |
1004 | #endif | |
1005 | } | |
1006 | ||
f6db1481 RH |
1007 | /* Try to identify useless null pointer tests and delete them. */ |
1008 | static void | |
1009 | rest_of_handle_null_pointer (tree decl, rtx insns) | |
1010 | { | |
1011 | open_dump_file (DFI_null, decl); | |
1012 | if (dump_file) | |
1013 | dump_flow_info (dump_file); | |
1014 | ||
1015 | if (delete_null_pointer_checks (insns)) | |
1016 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
1017 | ||
1018 | close_dump_file (DFI_null, print_rtl_with_bb, insns); | |
1019 | } | |
1020 | ||
1021 | /* Try combining insns through substitution. */ | |
1022 | static void | |
1023 | rest_of_handle_combine (tree decl, rtx insns) | |
1024 | { | |
1025 | int rebuild_jump_labels_after_combine = 0; | |
1026 | ||
1027 | timevar_push (TV_COMBINE); | |
1028 | open_dump_file (DFI_combine, decl); | |
1029 | ||
1030 | rebuild_jump_labels_after_combine | |
1031 | = combine_instructions (insns, max_reg_num ()); | |
1032 | ||
1033 | /* Combining insns may have turned an indirect jump into a | |
1034 | direct jump. Rebuild the JUMP_LABEL fields of jumping | |
1035 | instructions. */ | |
1036 | if (rebuild_jump_labels_after_combine) | |
1037 | { | |
1038 | timevar_push (TV_JUMP); | |
1039 | rebuild_jump_labels (insns); | |
1040 | timevar_pop (TV_JUMP); | |
1041 | ||
1042 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE); | |
1043 | } | |
1044 | ||
1045 | close_dump_file (DFI_combine, print_rtl_with_bb, insns); | |
1046 | timevar_pop (TV_COMBINE); | |
1047 | ||
1048 | ggc_collect (); | |
1049 | } | |
1050 | ||
1051 | /* Perform life analysis. */ | |
1052 | static void | |
1053 | rest_of_handle_life (tree decl, rtx insns) | |
1054 | { | |
1055 | open_dump_file (DFI_life, decl); | |
1056 | regclass_init (); | |
1057 | ||
1058 | #ifdef ENABLE_CHECKING | |
1059 | verify_flow_info (); | |
1060 | #endif | |
1061 | life_analysis (insns, dump_file, PROP_FINAL); | |
1062 | if (optimize) | |
1063 | cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_UPDATE_LIFE | |
1064 | | CLEANUP_LOG_LINKS | |
1065 | | (flag_thread_jumps ? CLEANUP_THREADING : 0)); | |
1066 | timevar_pop (TV_FLOW); | |
1067 | ||
6de9cd9a | 1068 | if (extra_warnings) |
f6db1481 | 1069 | { |
6de9cd9a DN |
1070 | setjmp_vars_warning (DECL_INITIAL (decl)); |
1071 | setjmp_args_warning (); | |
f6db1481 RH |
1072 | } |
1073 | ||
1074 | if (optimize) | |
1075 | { | |
1076 | if (!flag_new_regalloc && initialize_uninitialized_subregs ()) | |
1077 | { | |
1078 | /* Insns were inserted, and possibly pseudos created, so | |
1079 | things might look a bit different. */ | |
1080 | insns = get_insns (); | |
1081 | allocate_reg_life_data (); | |
1082 | update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES, | |
1083 | PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES); | |
1084 | } | |
1085 | } | |
1086 | ||
1087 | no_new_pseudos = 1; | |
1088 | ||
1089 | close_dump_file (DFI_life, print_rtl_with_bb, insns); | |
1090 | ||
1091 | ggc_collect (); | |
1092 | } | |
1093 | ||
1094 | /* Perform common subexpression elimination. Nonzero value from | |
1095 | `cse_main' means that jumps were simplified and some code may now | |
1096 | be unreachable, so do jump optimization again. */ | |
1097 | static void | |
1098 | rest_of_handle_cse (tree decl, rtx insns) | |
1099 | { | |
1100 | int tem; | |
1101 | ||
1102 | open_dump_file (DFI_cse, decl); | |
1103 | if (dump_file) | |
1104 | dump_flow_info (dump_file); | |
1105 | timevar_push (TV_CSE); | |
1106 | ||
1107 | reg_scan (insns, max_reg_num (), 1); | |
1108 | ||
1109 | tem = cse_main (insns, max_reg_num (), 0, dump_file); | |
1110 | if (tem) | |
1111 | rebuild_jump_labels (insns); | |
1112 | if (purge_all_dead_edges (0)) | |
1113 | delete_unreachable_blocks (); | |
1114 | ||
1115 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1116 | ||
1117 | /* If we are not running more CSE passes, then we are no longer | |
1118 | expecting CSE to be run. But always rerun it in a cheap mode. */ | |
1119 | cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse; | |
1120 | ||
1121 | if (tem || optimize > 1) | |
1122 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
1123 | /* Try to identify useless null pointer tests and delete them. */ | |
1124 | if (flag_delete_null_pointer_checks) | |
1125 | { | |
1126 | timevar_push (TV_JUMP); | |
1127 | ||
1128 | if (delete_null_pointer_checks (insns)) | |
1129 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
1130 | timevar_pop (TV_JUMP); | |
1131 | } | |
1132 | ||
1133 | /* The second pass of jump optimization is likely to have | |
1134 | removed a bunch more instructions. */ | |
1135 | renumber_insns (dump_file); | |
1136 | ||
1137 | timevar_pop (TV_CSE); | |
1138 | close_dump_file (DFI_cse, print_rtl_with_bb, insns); | |
1139 | } | |
1140 | ||
1141 | /* Run second CSE pass after loop optimizations. */ | |
1142 | static void | |
1143 | rest_of_handle_cse2 (tree decl, rtx insns) | |
1144 | { | |
1145 | int tem; | |
1146 | ||
1147 | timevar_push (TV_CSE2); | |
1148 | open_dump_file (DFI_cse2, decl); | |
1149 | if (dump_file) | |
1150 | dump_flow_info (dump_file); | |
1151 | /* CFG is no longer maintained up-to-date. */ | |
1152 | tem = cse_main (insns, max_reg_num (), 1, dump_file); | |
1153 | ||
1154 | /* Run a pass to eliminate duplicated assignments to condition code | |
1155 | registers. We have to run this after bypass_jumps, because it | |
1156 | makes it harder for that pass to determine whether a jump can be | |
1157 | bypassed safely. */ | |
1158 | cse_condition_code_reg (); | |
1159 | ||
1160 | purge_all_dead_edges (0); | |
1161 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1162 | ||
1163 | if (tem) | |
1164 | { | |
1165 | timevar_push (TV_JUMP); | |
1166 | rebuild_jump_labels (insns); | |
1167 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
1168 | timevar_pop (TV_JUMP); | |
1169 | } | |
1170 | reg_scan (insns, max_reg_num (), 0); | |
1171 | close_dump_file (DFI_cse2, print_rtl_with_bb, insns); | |
1172 | ggc_collect (); | |
1173 | timevar_pop (TV_CSE2); | |
1174 | } | |
1175 | ||
1176 | /* Perform global cse. */ | |
1177 | static void | |
1178 | rest_of_handle_gcse (tree decl, rtx insns) | |
1179 | { | |
1180 | int save_csb, save_cfj; | |
1181 | int tem2 = 0, tem; | |
1182 | ||
1183 | timevar_push (TV_GCSE); | |
1184 | open_dump_file (DFI_gcse, decl); | |
1185 | ||
1186 | tem = gcse_main (insns, dump_file); | |
1187 | rebuild_jump_labels (insns); | |
1188 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1189 | ||
1190 | save_csb = flag_cse_skip_blocks; | |
1191 | save_cfj = flag_cse_follow_jumps; | |
1192 | flag_cse_skip_blocks = flag_cse_follow_jumps = 0; | |
1193 | ||
f6db1481 RH |
1194 | /* If -fexpensive-optimizations, re-run CSE to clean up things done |
1195 | by gcse. */ | |
1196 | if (flag_expensive_optimizations) | |
1197 | { | |
1198 | timevar_push (TV_CSE); | |
1199 | reg_scan (insns, max_reg_num (), 1); | |
1200 | tem2 = cse_main (insns, max_reg_num (), 0, dump_file); | |
1201 | purge_all_dead_edges (0); | |
1202 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1203 | timevar_pop (TV_CSE); | |
1204 | cse_not_expected = !flag_rerun_cse_after_loop; | |
1205 | } | |
1206 | ||
1207 | /* If gcse or cse altered any jumps, rerun jump optimizations to clean | |
1208 | things up. Then possibly re-run CSE again. */ | |
1209 | while (tem || tem2) | |
1210 | { | |
1211 | tem = tem2 = 0; | |
1212 | timevar_push (TV_JUMP); | |
1213 | rebuild_jump_labels (insns); | |
1214 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
1215 | timevar_pop (TV_JUMP); | |
1216 | ||
1217 | if (flag_expensive_optimizations) | |
1218 | { | |
1219 | timevar_push (TV_CSE); | |
1220 | reg_scan (insns, max_reg_num (), 1); | |
1221 | tem2 = cse_main (insns, max_reg_num (), 0, dump_file); | |
1222 | purge_all_dead_edges (0); | |
1223 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1224 | timevar_pop (TV_CSE); | |
1225 | } | |
1226 | } | |
1227 | ||
1228 | close_dump_file (DFI_gcse, print_rtl_with_bb, insns); | |
1229 | timevar_pop (TV_GCSE); | |
1230 | ||
1231 | ggc_collect (); | |
1232 | flag_cse_skip_blocks = save_csb; | |
1233 | flag_cse_follow_jumps = save_cfj; | |
1234 | #ifdef ENABLE_CHECKING | |
1235 | verify_flow_info (); | |
1236 | #endif | |
1237 | } | |
1238 | ||
1239 | /* Move constant computations out of loops. */ | |
1240 | static void | |
1241 | rest_of_handle_loop_optimize (tree decl, rtx insns) | |
1242 | { | |
1243 | int do_unroll, do_prefetch; | |
1244 | ||
1245 | timevar_push (TV_LOOP); | |
1246 | delete_dead_jumptables (); | |
1247 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
1248 | open_dump_file (DFI_loop, decl); | |
1249 | ||
1250 | /* CFG is no longer maintained up-to-date. */ | |
1251 | free_bb_for_insn (); | |
1252 | ||
1253 | if (flag_unroll_loops) | |
1254 | do_unroll = LOOP_AUTO_UNROLL; /* Having two unrollers is useless. */ | |
1255 | else | |
1256 | do_unroll = flag_old_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL; | |
1257 | do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0; | |
1258 | ||
1259 | if (flag_rerun_loop_opt) | |
1260 | { | |
1261 | cleanup_barriers (); | |
1262 | ||
1263 | /* We only want to perform unrolling once. */ | |
1264 | loop_optimize (insns, dump_file, do_unroll); | |
1265 | do_unroll = 0; | |
1266 | ||
1267 | /* The first call to loop_optimize makes some instructions | |
1268 | trivially dead. We delete those instructions now in the | |
1269 | hope that doing so will make the heuristics in loop work | |
1270 | better and possibly speed up compilation. */ | |
1271 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1272 | ||
1273 | /* The regscan pass is currently necessary as the alias | |
1274 | analysis code depends on this information. */ | |
1275 | reg_scan (insns, max_reg_num (), 1); | |
1276 | } | |
1277 | cleanup_barriers (); | |
689ba89d | 1278 | loop_optimize (insns, dump_file, do_unroll | do_prefetch); |
f6db1481 RH |
1279 | |
1280 | /* Loop can create trivially dead instructions. */ | |
1281 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1282 | close_dump_file (DFI_loop, print_rtl, insns); | |
1283 | timevar_pop (TV_LOOP); | |
1284 | find_basic_blocks (insns, max_reg_num (), dump_file); | |
1285 | ||
1286 | ggc_collect (); | |
1287 | } | |
1288 | ||
1289 | /* Perform loop optimizations. It might be better to do them a bit | |
1290 | sooner, but we want the profile feedback to work more | |
1291 | efficiently. */ | |
1292 | static void | |
1293 | rest_of_handle_loop2 (tree decl, rtx insns) | |
1294 | { | |
1295 | struct loops *loops; | |
1296 | basic_block bb; | |
1297 | ||
689ba89d ZD |
1298 | if (!flag_unswitch_loops |
1299 | && !flag_peel_loops | |
1300 | && !flag_unroll_loops | |
1301 | && !flag_branch_on_count_reg) | |
1302 | return; | |
1303 | ||
f6db1481 RH |
1304 | timevar_push (TV_LOOP); |
1305 | open_dump_file (DFI_loop2, decl); | |
1306 | if (dump_file) | |
1307 | dump_flow_info (dump_file); | |
1308 | ||
1309 | /* Initialize structures for layout changes. */ | |
1310 | cfg_layout_initialize (); | |
1311 | ||
1312 | loops = loop_optimizer_init (dump_file); | |
1313 | ||
1314 | if (loops) | |
1315 | { | |
1316 | /* The optimizations: */ | |
1317 | if (flag_unswitch_loops) | |
1318 | unswitch_loops (loops); | |
1319 | ||
1320 | if (flag_peel_loops || flag_unroll_loops) | |
1321 | unroll_and_peel_loops (loops, | |
1322 | (flag_peel_loops ? UAP_PEEL : 0) | | |
1323 | (flag_unroll_loops ? UAP_UNROLL : 0) | | |
1324 | (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0)); | |
1325 | ||
689ba89d ZD |
1326 | #ifdef HAVE_doloop_end |
1327 | if (flag_branch_on_count_reg && HAVE_doloop_end) | |
1328 | doloop_optimize_loops (loops); | |
1329 | #endif /* HAVE_doloop_end */ | |
1330 | ||
f6db1481 RH |
1331 | loop_optimizer_finalize (loops, dump_file); |
1332 | } | |
1333 | ||
1334 | /* Finalize layout changes. */ | |
1335 | FOR_EACH_BB (bb) | |
1336 | if (bb->next_bb != EXIT_BLOCK_PTR) | |
1337 | bb->rbi->next = bb->next_bb; | |
1338 | cfg_layout_finalize (); | |
1339 | ||
1340 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
1341 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1342 | reg_scan (insns, max_reg_num (), 0); | |
1343 | if (dump_file) | |
1344 | dump_flow_info (dump_file); | |
1345 | close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ()); | |
1346 | timevar_pop (TV_LOOP); | |
1347 | ggc_collect (); | |
1348 | } | |
1349 | ||
1350 | /* This is called from finish_function (within langhooks.parse_file) | |
1351 | after each top-level definition is parsed. | |
1352 | It is supposed to compile that function or variable | |
1353 | and output the assembler code for it. | |
1354 | After we return, the tree storage is freed. */ | |
1355 | ||
1356 | void | |
1357 | rest_of_compilation (tree decl) | |
1358 | { | |
1359 | rtx insns; | |
1360 | ||
1361 | timevar_push (TV_REST_OF_COMPILATION); | |
1362 | ||
1363 | /* Register rtl specific functions for cfg. */ | |
1364 | rtl_register_cfg_hooks (); | |
1365 | ||
1366 | /* Now that we're out of the frontend, we shouldn't have any more | |
1367 | CONCATs anywhere. */ | |
1368 | generating_concat_p = 0; | |
1369 | ||
1370 | /* When processing delayed functions, prepare_function_start() won't | |
1371 | have been run to re-initialize it. */ | |
1372 | cse_not_expected = ! optimize; | |
1373 | ||
6de9cd9a DN |
1374 | if (!cfun->dont_emit_block_notes) |
1375 | { | |
1376 | /* First, make sure that NOTE_BLOCK is set correctly for each | |
1377 | NOTE_INSN_BLOCK_BEG/NOTE_INSN_BLOCK_END note. */ | |
1378 | if (!cfun->x_whole_function_mode_p) | |
1379 | identify_blocks (); | |
1380 | ||
1381 | /* In function-at-a-time mode, we do not attempt to keep the BLOCK | |
1382 | tree in sensible shape. So, we just recalculate it here. */ | |
1383 | if (cfun->x_whole_function_mode_p) | |
1384 | reorder_blocks (); | |
1385 | } | |
1386 | else | |
1387 | finalize_block_changes (); | |
f6db1481 RH |
1388 | |
1389 | init_flow (); | |
1390 | ||
6de9cd9a DN |
1391 | /* Dump the rtl code if we are dumping rtl. */ |
1392 | if (open_dump_file (DFI_rtl, decl)) | |
1393 | close_dump_file (DFI_rtl, print_rtl, get_insns ()); | |
1394 | ||
1395 | /* Convert from NOTE_INSN_EH_REGION style notes, and do other | |
1396 | sorts of eh initialization. Delay this until after the | |
1397 | initial rtl dump so that we can see the original nesting. */ | |
1398 | convert_from_eh_region_ranges (); | |
f6db1481 RH |
1399 | |
1400 | /* If we're emitting a nested function, make sure its parent gets | |
1401 | emitted as well. Doing otherwise confuses debug info. */ | |
1402 | { | |
1403 | tree parent; | |
1404 | for (parent = DECL_CONTEXT (current_function_decl); | |
1405 | parent != NULL_TREE; | |
1406 | parent = get_containing_scope (parent)) | |
1407 | if (TREE_CODE (parent) == FUNCTION_DECL) | |
1408 | TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1; | |
1409 | } | |
1410 | ||
1411 | /* We are now committed to emitting code for this function. Do any | |
1412 | preparation, such as emitting abstract debug info for the inline | |
1413 | before it gets mangled by optimization. */ | |
1414 | if (cgraph_function_possibly_inlined_p (decl)) | |
1415 | (*debug_hooks->outlining_inline_function) (decl); | |
1416 | ||
1417 | /* Remove any notes we don't need. That will make iterating | |
1418 | over the instruction sequence faster, and allow the garbage | |
1419 | collector to reclaim the memory used by the notes. */ | |
1420 | remove_unnecessary_notes (); | |
6de9cd9a DN |
1421 | if (!cfun->dont_emit_block_notes) |
1422 | reorder_blocks (); | |
f6db1481 RH |
1423 | |
1424 | ggc_collect (); | |
1425 | ||
1426 | /* Initialize some variables used by the optimizers. */ | |
1427 | init_function_for_compilation (); | |
1428 | ||
1429 | if (! DECL_DEFER_OUTPUT (decl)) | |
1430 | TREE_ASM_WRITTEN (decl) = 1; | |
1431 | ||
1432 | /* Now that integrate will no longer see our rtl, we need not | |
1433 | distinguish between the return value of this function and the | |
1434 | return value of called functions. Also, we can remove all SETs | |
1435 | of subregs of hard registers; they are only here because of | |
1436 | integrate. Also, we can now initialize pseudos intended to | |
1437 | carry magic hard reg data throughout the function. */ | |
1438 | rtx_equal_function_value_matters = 0; | |
1439 | purge_hard_subreg_sets (get_insns ()); | |
1440 | ||
1441 | /* Early return if there were errors. We can run afoul of our | |
1442 | consistency checks, and there's not really much point in fixing them. | |
1443 | Don't return yet if -Wreturn-type; we need to do cleanup_cfg. */ | |
1444 | if (((rtl_dump_and_exit || flag_syntax_only) && !warn_return_type) | |
1445 | || errorcount || sorrycount) | |
1446 | goto exit_rest_of_compilation; | |
1447 | ||
1448 | timevar_push (TV_JUMP); | |
1449 | open_dump_file (DFI_sibling, decl); | |
1450 | insns = get_insns (); | |
1451 | rebuild_jump_labels (insns); | |
1452 | find_exception_handler_labels (); | |
1453 | find_basic_blocks (insns, max_reg_num (), dump_file); | |
1454 | ||
1455 | delete_unreachable_blocks (); | |
1456 | ||
1457 | /* Turn NOTE_INSN_PREDICTIONs into branch predictions. */ | |
1458 | if (flag_guess_branch_prob) | |
1459 | { | |
1460 | timevar_push (TV_BRANCH_PROB); | |
1461 | note_prediction_to_br_prob (); | |
1462 | timevar_pop (TV_BRANCH_PROB); | |
1463 | } | |
1464 | ||
f6db1481 RH |
1465 | timevar_pop (TV_JUMP); |
1466 | ||
6de9cd9a DN |
1467 | if (cfun->tail_call_emit) |
1468 | fixup_tail_calls (); | |
1469 | ||
f6db1481 RH |
1470 | insn_locators_initialize (); |
1471 | /* Complete generation of exception handling code. */ | |
1472 | if (doing_eh (0)) | |
1473 | { | |
1474 | timevar_push (TV_JUMP); | |
1475 | open_dump_file (DFI_eh, decl); | |
1476 | ||
1477 | finish_eh_generation (); | |
1478 | ||
1479 | close_dump_file (DFI_eh, print_rtl, get_insns ()); | |
1480 | timevar_pop (TV_JUMP); | |
1481 | } | |
1482 | ||
1483 | /* Delay emitting hard_reg_initial_value sets until after EH landing pad | |
1484 | generation, which might create new sets. */ | |
1485 | emit_initial_value_sets (); | |
1486 | ||
1487 | #ifdef FINALIZE_PIC | |
1488 | /* If we are doing position-independent code generation, now | |
1489 | is the time to output special prologues and epilogues. | |
1490 | We do not want to do this earlier, because it just clutters | |
1491 | up inline functions with meaningless insns. */ | |
1492 | if (flag_pic) | |
1493 | FINALIZE_PIC; | |
1494 | #endif | |
1495 | ||
1496 | insns = get_insns (); | |
1497 | ||
1498 | /* Copy any shared structure that should not be shared. */ | |
1499 | unshare_all_rtl (current_function_decl, insns); | |
1500 | ||
1501 | #ifdef SETJMP_VIA_SAVE_AREA | |
1502 | /* This must be performed before virtual register instantiation. | |
d1a6adeb | 1503 | Please be aware that everything in the compiler that can look |
f6db1481 RH |
1504 | at the RTL up to this point must understand that REG_SAVE_AREA |
1505 | is just like a use of the REG contained inside. */ | |
1506 | if (current_function_calls_alloca) | |
1507 | optimize_save_area_alloca (insns); | |
1508 | #endif | |
1509 | ||
1510 | /* Instantiate all virtual registers. */ | |
1511 | instantiate_virtual_regs (current_function_decl, insns); | |
1512 | ||
1513 | open_dump_file (DFI_jump, decl); | |
1514 | ||
1515 | /* Always do one jump optimization pass to ensure that JUMP_LABEL fields | |
1516 | are initialized and to compute whether control can drop off the end | |
1517 | of the function. */ | |
1518 | ||
1519 | timevar_push (TV_JUMP); | |
1520 | /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this | |
1521 | before jump optimization switches branch directions. */ | |
1522 | if (flag_guess_branch_prob) | |
1523 | expected_value_to_br_prob (); | |
1524 | ||
1525 | reg_scan (insns, max_reg_num (), 0); | |
1526 | rebuild_jump_labels (insns); | |
1527 | find_basic_blocks (insns, max_reg_num (), dump_file); | |
1528 | delete_trivially_dead_insns (insns, max_reg_num ()); | |
1529 | if (dump_file) | |
1530 | dump_flow_info (dump_file); | |
1531 | cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP | |
1532 | | (flag_thread_jumps ? CLEANUP_THREADING : 0)); | |
1533 | ||
6de9cd9a DN |
1534 | create_loop_notes (); |
1535 | ||
f6db1481 RH |
1536 | purge_line_number_notes (insns); |
1537 | ||
1538 | timevar_pop (TV_JUMP); | |
1539 | close_dump_file (DFI_jump, print_rtl, insns); | |
1540 | ||
1541 | /* Now is when we stop if -fsyntax-only and -Wreturn-type. */ | |
1542 | if (rtl_dump_and_exit || flag_syntax_only || DECL_DEFER_OUTPUT (decl)) | |
1543 | goto exit_rest_of_compilation; | |
1544 | ||
1545 | timevar_push (TV_JUMP); | |
1546 | ||
1547 | if (optimize) | |
1548 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
1549 | ||
1550 | if (flag_delete_null_pointer_checks) | |
1551 | rest_of_handle_null_pointer (decl, insns); | |
1552 | ||
1553 | /* Jump optimization, and the removal of NULL pointer checks, may | |
1554 | have reduced the number of instructions substantially. CSE, and | |
1555 | future passes, allocate arrays whose dimensions involve the | |
1556 | maximum instruction UID, so if we can reduce the maximum UID | |
1557 | we'll save big on memory. */ | |
1558 | renumber_insns (dump_file); | |
1559 | timevar_pop (TV_JUMP); | |
1560 | ||
1561 | close_dump_file (DFI_jump, print_rtl_with_bb, insns); | |
1562 | ||
1563 | ggc_collect (); | |
1564 | ||
1565 | if (optimize > 0) | |
1566 | rest_of_handle_cse (decl, insns); | |
1567 | ||
1568 | rest_of_handle_addressof (decl, insns); | |
1569 | ||
1570 | ggc_collect (); | |
1571 | ||
1572 | if (optimize > 0) | |
1573 | { | |
1574 | if (flag_gcse) | |
1575 | rest_of_handle_gcse (decl, insns); | |
1576 | ||
1577 | if (flag_loop_optimize) | |
1578 | rest_of_handle_loop_optimize (decl, insns); | |
1579 | ||
1580 | if (flag_gcse) | |
1581 | rest_of_handle_jump_bypass (decl, insns); | |
1582 | } | |
1583 | ||
1584 | timevar_push (TV_FLOW); | |
1585 | ||
1586 | rest_of_handle_cfg (decl, insns); | |
1587 | ||
6de9cd9a DN |
1588 | if (!flag_tree_based_profiling |
1589 | && (optimize > 0 || profile_arc_flag | |
1590 | || flag_test_coverage || flag_branch_probabilities)) | |
f6db1481 | 1591 | { |
6de9cd9a DN |
1592 | rtl_register_profile_hooks (); |
1593 | rtl_register_value_prof_hooks (); | |
f6db1481 RH |
1594 | rest_of_handle_branch_prob (decl, insns); |
1595 | ||
1596 | if (flag_branch_probabilities | |
1597 | && flag_profile_values | |
1598 | && flag_value_profile_transformations) | |
1599 | rest_of_handle_value_profile_transformations (decl, insns); | |
1600 | ||
1601 | /* Remove the death notes created for vpt. */ | |
1602 | if (flag_profile_values) | |
1603 | count_or_remove_death_notes (NULL, 1); | |
1604 | } | |
1605 | ||
1606 | if (optimize > 0) | |
1607 | rest_of_handle_if_conversion (decl, insns); | |
1608 | ||
1609 | if (flag_tracer) | |
1610 | rest_of_handle_tracer (decl, insns); | |
1611 | ||
689ba89d | 1612 | if (optimize > 0) |
f6db1481 RH |
1613 | rest_of_handle_loop2 (decl, insns); |
1614 | ||
1615 | if (flag_web) | |
1616 | rest_of_handle_web (decl, insns); | |
1617 | ||
1618 | if (flag_rerun_cse_after_loop) | |
1619 | rest_of_handle_cse2 (decl, insns); | |
1620 | ||
1621 | cse_not_expected = 1; | |
1622 | ||
1623 | rest_of_handle_life (decl, insns); | |
1624 | ||
1625 | if (optimize > 0) | |
1626 | rest_of_handle_combine (decl, insns); | |
1627 | ||
1628 | if (flag_if_conversion) | |
1629 | rest_of_handle_if_after_combine (decl, insns); | |
1630 | ||
750054a2 CT |
1631 | /* The optimization to partition hot/cold basic blocks into separate |
1632 | sections of the .o file does not work well with exception handling. | |
1633 | Don't call it if there are exceptions. */ | |
1634 | ||
1635 | if (flag_reorder_blocks_and_partition && !flag_exceptions) | |
1636 | { | |
1637 | no_new_pseudos = 0; | |
1638 | partition_hot_cold_basic_blocks (); | |
1639 | allocate_reg_life_data (); | |
1640 | update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES, | |
1641 | PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES); | |
1642 | no_new_pseudos = 1; | |
1643 | } | |
1644 | ||
f6db1481 RH |
1645 | if (optimize > 0 && (flag_regmove || flag_expensive_optimizations)) |
1646 | rest_of_handle_regmove (decl, insns); | |
1647 | ||
1648 | /* Do unconditional splitting before register allocation to allow machine | |
1649 | description to add extra information not needed previously. */ | |
1650 | split_all_insns (1); | |
1651 | ||
1652 | #ifdef OPTIMIZE_MODE_SWITCHING | |
1653 | timevar_push (TV_MODE_SWITCH); | |
1654 | ||
1655 | no_new_pseudos = 0; | |
1656 | optimize_mode_switching (NULL); | |
1657 | no_new_pseudos = 1; | |
1658 | ||
1659 | timevar_pop (TV_MODE_SWITCH); | |
1660 | #endif | |
1661 | ||
1662 | /* Any of the several passes since flow1 will have munged register | |
1663 | lifetime data a bit. We need it to be up to date for scheduling | |
1664 | (see handling of reg_known_equiv in init_alias_analysis). */ | |
1665 | recompute_reg_usage (insns, !optimize_size); | |
1666 | ||
1667 | #ifdef INSN_SCHEDULING | |
1668 | rest_of_handle_sched (decl, insns); | |
1669 | #endif | |
1670 | ||
1671 | /* Determine if the current function is a leaf before running reload | |
1672 | since this can impact optimizations done by the prologue and | |
1673 | epilogue thus changing register elimination offsets. */ | |
1674 | current_function_is_leaf = leaf_function_p (); | |
1675 | ||
1676 | timevar_push (TV_LOCAL_ALLOC); | |
1677 | open_dump_file (DFI_lreg, decl); | |
1678 | ||
1679 | if (flag_new_regalloc) | |
1680 | { | |
1681 | if (rest_of_handle_new_regalloc (decl, insns)) | |
1682 | goto exit_rest_of_compilation; | |
1683 | } | |
1684 | else | |
1685 | { | |
1686 | if (rest_of_handle_old_regalloc (decl, insns)) | |
1687 | goto exit_rest_of_compilation; | |
1688 | } | |
1689 | ||
1690 | ggc_collect (); | |
1691 | ||
1692 | open_dump_file (DFI_postreload, decl); | |
1693 | ||
1694 | /* Do a very simple CSE pass over just the hard registers. */ | |
1695 | if (optimize > 0) | |
1696 | { | |
1697 | timevar_push (TV_RELOAD_CSE_REGS); | |
1698 | reload_cse_regs (insns); | |
1699 | /* reload_cse_regs can eliminate potentially-trapping MEMs. | |
1700 | Remove any EH edges associated with them. */ | |
1701 | if (flag_non_call_exceptions) | |
1702 | purge_all_dead_edges (0); | |
1703 | timevar_pop (TV_RELOAD_CSE_REGS); | |
1704 | } | |
1705 | ||
1706 | close_dump_file (DFI_postreload, print_rtl_with_bb, insns); | |
1707 | ||
f9957958 MH |
1708 | if (optimize > 0 && flag_gcse_after_reload) |
1709 | rest_of_handle_gcse2 (decl, insns); | |
1710 | ||
f6db1481 RH |
1711 | /* Re-create the death notes which were deleted during reload. */ |
1712 | timevar_push (TV_FLOW2); | |
1713 | open_dump_file (DFI_flow2, decl); | |
1714 | ||
1715 | #ifdef ENABLE_CHECKING | |
1716 | verify_flow_info (); | |
1717 | #endif | |
1718 | ||
1719 | /* If optimizing, then go ahead and split insns now. */ | |
1720 | #ifndef STACK_REGS | |
1721 | if (optimize > 0) | |
1722 | #endif | |
1723 | split_all_insns (0); | |
1724 | ||
1725 | if (flag_branch_target_load_optimize) | |
1726 | { | |
1727 | open_dump_file (DFI_branch_target_load, decl); | |
1728 | ||
1729 | branch_target_load_optimize (insns, false); | |
1730 | ||
1731 | close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns); | |
1732 | ||
1733 | ggc_collect (); | |
1734 | } | |
1735 | ||
1736 | if (optimize) | |
1737 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
1738 | ||
1739 | /* On some machines, the prologue and epilogue code, or parts thereof, | |
1740 | can be represented as RTL. Doing so lets us schedule insns between | |
1741 | it and the rest of the code and also allows delayed branch | |
1742 | scheduling to operate in the epilogue. */ | |
1743 | thread_prologue_and_epilogue_insns (insns); | |
1744 | epilogue_completed = 1; | |
1745 | ||
1746 | if (optimize) | |
1747 | { | |
1748 | life_analysis (insns, dump_file, PROP_POSTRELOAD); | |
1749 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE | |
1750 | | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0)); | |
1751 | ||
1752 | /* This is kind of a heuristic. We need to run combine_stack_adjustments | |
1753 | even for machines with possibly nonzero RETURN_POPS_ARGS | |
1754 | and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having | |
1755 | push instructions will have popping returns. */ | |
1756 | #ifndef PUSH_ROUNDING | |
1757 | if (!ACCUMULATE_OUTGOING_ARGS) | |
1758 | #endif | |
1759 | combine_stack_adjustments (); | |
1760 | ||
1761 | ggc_collect (); | |
1762 | } | |
1763 | ||
1764 | flow2_completed = 1; | |
1765 | ||
1766 | close_dump_file (DFI_flow2, print_rtl_with_bb, insns); | |
1767 | timevar_pop (TV_FLOW2); | |
1768 | ||
1769 | #ifdef HAVE_peephole2 | |
1770 | if (optimize > 0 && flag_peephole2) | |
1771 | { | |
1772 | timevar_push (TV_PEEPHOLE2); | |
1773 | open_dump_file (DFI_peephole2, decl); | |
1774 | ||
1775 | peephole2_optimize (dump_file); | |
1776 | ||
1777 | close_dump_file (DFI_peephole2, print_rtl_with_bb, insns); | |
1778 | timevar_pop (TV_PEEPHOLE2); | |
1779 | } | |
1780 | #endif | |
1781 | ||
1782 | open_dump_file (DFI_ce3, decl); | |
1783 | if (optimize) | |
1784 | /* Last attempt to optimize CFG, as scheduling, peepholing and insn | |
1785 | splitting possibly introduced more crossjumping opportunities. */ | |
1786 | cleanup_cfg (CLEANUP_EXPENSIVE | |
1787 | | CLEANUP_UPDATE_LIFE | |
1788 | | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0)); | |
1789 | if (flag_if_conversion2) | |
1790 | { | |
1791 | timevar_push (TV_IFCVT2); | |
1792 | ||
1793 | if_convert (1); | |
1794 | ||
1795 | timevar_pop (TV_IFCVT2); | |
1796 | } | |
1797 | close_dump_file (DFI_ce3, print_rtl_with_bb, insns); | |
1798 | ||
1799 | if (optimize > 0) | |
1800 | { | |
1801 | if (flag_rename_registers || flag_cprop_registers) | |
1802 | rest_of_handle_regrename (decl, insns); | |
1803 | ||
1804 | rest_of_handle_reorder_blocks (decl, insns); | |
1805 | } | |
1806 | ||
1807 | if (flag_branch_target_load_optimize2) | |
1808 | { | |
1809 | /* Leave this a warning for now so that it is possible to experiment | |
1810 | with running this pass twice. In 3.6, we should either make this | |
1811 | an error, or use separate dump files. */ | |
1812 | if (flag_branch_target_load_optimize) | |
1813 | warning ("branch target register load optimization is not intended " | |
1814 | "to be run twice"); | |
1815 | ||
1816 | open_dump_file (DFI_branch_target_load, decl); | |
1817 | ||
1818 | branch_target_load_optimize (insns, true); | |
1819 | ||
1820 | close_dump_file (DFI_branch_target_load, print_rtl_with_bb, insns); | |
1821 | ||
1822 | ggc_collect (); | |
1823 | } | |
1824 | ||
1825 | #ifdef INSN_SCHEDULING | |
1826 | if (optimize > 0 && flag_schedule_insns_after_reload) | |
1827 | rest_of_handle_sched2 (decl, insns); | |
1828 | #endif | |
1829 | ||
1830 | #ifdef LEAF_REGISTERS | |
1831 | current_function_uses_only_leaf_regs | |
1832 | = optimize > 0 && only_leaf_regs_used () && leaf_function_p (); | |
1833 | #endif | |
1834 | ||
1835 | #ifdef STACK_REGS | |
1836 | rest_of_handle_stack_regs (decl, insns); | |
1837 | #endif | |
1838 | ||
1839 | compute_alignments (); | |
1840 | ||
1841 | if (flag_var_tracking) | |
1842 | rest_of_handle_variable_tracking (decl, insns); | |
1843 | ||
1844 | /* CFG is no longer maintained up-to-date. */ | |
1845 | free_bb_for_insn (); | |
1846 | ||
1847 | if (targetm.machine_dependent_reorg != 0) | |
1848 | rest_of_handle_machine_reorg (decl, insns); | |
1849 | ||
1850 | purge_line_number_notes (insns); | |
1851 | cleanup_barriers (); | |
1852 | ||
1853 | #ifdef DELAY_SLOTS | |
1854 | if (optimize > 0 && flag_delayed_branch) | |
1855 | rest_of_handle_delay_slots (decl, insns); | |
1856 | #endif | |
1857 | ||
1858 | #if defined (HAVE_ATTR_length) && !defined (STACK_REGS) | |
1859 | timevar_push (TV_SHORTEN_BRANCH); | |
1860 | split_all_insns_noflow (); | |
1861 | timevar_pop (TV_SHORTEN_BRANCH); | |
1862 | #endif | |
1863 | ||
1864 | convert_to_eh_region_ranges (); | |
1865 | ||
1866 | /* Shorten branches. */ | |
1867 | timevar_push (TV_SHORTEN_BRANCH); | |
1868 | shorten_branches (get_insns ()); | |
1869 | timevar_pop (TV_SHORTEN_BRANCH); | |
1870 | ||
1871 | set_nothrow_function_flags (); | |
1872 | if (current_function_nothrow) | |
1873 | /* Now we know that this can't throw; set the flag for the benefit | |
1874 | of other functions later in this translation unit. */ | |
1875 | TREE_NOTHROW (current_function_decl) = 1; | |
1876 | ||
1877 | rest_of_handle_final (decl, insns); | |
1878 | ||
1879 | /* Write DBX symbols if requested. */ | |
1880 | ||
1881 | /* Note that for those inline functions where we don't initially | |
1882 | know for certain that we will be generating an out-of-line copy, | |
1883 | the first invocation of this routine (rest_of_compilation) will | |
1884 | skip over this code by doing a `goto exit_rest_of_compilation;'. | |
1885 | Later on, wrapup_global_declarations will (indirectly) call | |
1886 | rest_of_compilation again for those inline functions that need | |
1887 | to have out-of-line copies generated. During that call, we | |
1888 | *will* be routed past here. */ | |
1889 | ||
1890 | timevar_push (TV_SYMOUT); | |
1891 | (*debug_hooks->function_decl) (decl); | |
1892 | timevar_pop (TV_SYMOUT); | |
1893 | ||
1894 | exit_rest_of_compilation: | |
1895 | ||
1896 | coverage_end_function (); | |
1897 | ||
1898 | /* In case the function was not output, | |
1899 | don't leave any temporary anonymous types | |
1900 | queued up for sdb output. */ | |
1901 | #ifdef SDB_DEBUGGING_INFO | |
1902 | if (write_symbols == SDB_DEBUG) | |
1903 | sdbout_types (NULL_TREE); | |
1904 | #endif | |
1905 | ||
1906 | reload_completed = 0; | |
1907 | epilogue_completed = 0; | |
1908 | flow2_completed = 0; | |
1909 | no_new_pseudos = 0; | |
1910 | ||
1911 | timevar_push (TV_FINAL); | |
1912 | ||
1913 | /* Clear out the insn_length contents now that they are no | |
1914 | longer valid. */ | |
1915 | init_insn_lengths (); | |
1916 | ||
1917 | /* Show no temporary slots allocated. */ | |
1918 | init_temp_slots (); | |
1919 | ||
bb8a619e | 1920 | free_basic_block_vars (); |
f6db1481 RH |
1921 | free_bb_for_insn (); |
1922 | ||
1923 | timevar_pop (TV_FINAL); | |
1924 | ||
5fd9b178 | 1925 | if (targetm.binds_local_p (current_function_decl)) |
f6db1481 RH |
1926 | { |
1927 | int pref = cfun->preferred_stack_boundary; | |
1928 | if (cfun->recursive_call_emit | |
1929 | && cfun->stack_alignment_needed > cfun->preferred_stack_boundary) | |
1930 | pref = cfun->stack_alignment_needed; | |
1931 | cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary | |
1932 | = pref; | |
1933 | } | |
1934 | ||
1935 | /* Make sure volatile mem refs aren't considered valid operands for | |
1936 | arithmetic insns. We must call this here if this is a nested inline | |
1937 | function, since the above code leaves us in the init_recog state | |
1938 | (from final.c), and the function context push/pop code does not | |
1939 | save/restore volatile_ok. | |
1940 | ||
1941 | ??? Maybe it isn't necessary for expand_start_function to call this | |
1942 | anymore if we do it here? */ | |
1943 | ||
1944 | init_recog_no_volatile (); | |
1945 | ||
1946 | /* We're done with this function. Free up memory if we can. */ | |
1947 | free_after_parsing (cfun); | |
f6db1481 RH |
1948 | |
1949 | ggc_collect (); | |
1950 | ||
1951 | timevar_pop (TV_REST_OF_COMPILATION); | |
1952 | } | |
1953 | ||
1954 | void | |
1955 | init_optimization_passes (void) | |
1956 | { | |
6868bb1c JH |
1957 | open_dump_file (DFI_cgraph, NULL); |
1958 | cgraph_dump_file = dump_file; | |
1959 | dump_file = NULL; | |
f6db1481 RH |
1960 | } |
1961 | ||
1962 | void | |
1963 | finish_optimization_passes (void) | |
1964 | { | |
1965 | if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities) | |
1966 | { | |
1967 | timevar_push (TV_DUMP); | |
1968 | open_dump_file (DFI_bp, NULL); | |
1969 | ||
1970 | end_branch_prob (); | |
1971 | ||
1972 | close_dump_file (DFI_bp, NULL, NULL_RTX); | |
1973 | timevar_pop (TV_DUMP); | |
1974 | } | |
1975 | ||
1976 | if (optimize > 0 && open_dump_file (DFI_combine, NULL)) | |
1977 | { | |
1978 | timevar_push (TV_DUMP); | |
1979 | dump_combine_total_stats (dump_file); | |
1980 | close_dump_file (DFI_combine, NULL, NULL_RTX); | |
1981 | timevar_pop (TV_DUMP); | |
1982 | } | |
1983 | ||
6868bb1c JH |
1984 | dump_file = cgraph_dump_file; |
1985 | cgraph_dump_file = NULL; | |
1986 | close_dump_file (DFI_cgraph, NULL, NULL_RTX); | |
f6db1481 RH |
1987 | |
1988 | /* Do whatever is necessary to finish printing the graphs. */ | |
1989 | if (graph_dump_format != no_graph) | |
1990 | { | |
1991 | int i; | |
1992 | ||
1993 | for (i = 0; i < (int) DFI_MAX; ++i) | |
1994 | if (dump_file_tbl[i].initialized && dump_file_tbl[i].graph_dump_p) | |
1995 | { | |
1996 | char seq[16]; | |
1997 | char *suffix; | |
1998 | ||
1999 | sprintf (seq, DUMPFILE_FORMAT, i); | |
2000 | suffix = concat (seq, dump_file_tbl[i].extension, NULL); | |
2001 | finish_graph_dump_file (dump_base_name, suffix); | |
2002 | free (suffix); | |
2003 | } | |
2004 | } | |
2005 | ||
2006 | } | |
2007 | ||
2008 | bool | |
2009 | enable_rtl_dump_file (int letter) | |
2010 | { | |
2011 | bool matched = false; | |
2012 | int i; | |
2013 | ||
2014 | if (letter == 'a') | |
2015 | { | |
2016 | for (i = 0; i < (int) DFI_MAX; ++i) | |
2017 | dump_file_tbl[i].enabled = 1; | |
2018 | matched = true; | |
2019 | } | |
2020 | else | |
2021 | { | |
2022 | for (i = 0; i < (int) DFI_MAX; ++i) | |
2023 | if (letter == dump_file_tbl[i].debug_switch) | |
2024 | { | |
2025 | dump_file_tbl[i].enabled = 1; | |
2026 | matched = true; | |
2027 | } | |
2028 | } | |
2029 | ||
2030 | return matched; | |
2031 | } |