]>
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, | |
cd280abb | 3 | 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
f6db1481 RH |
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 | |
366ccddb KC |
19 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
20 | 02110-1301, USA. */ | |
f6db1481 RH |
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" | |
f6db1481 RH |
63 | #include "regs.h" |
64 | #include "timevar.h" | |
65 | #include "diagnostic.h" | |
66 | #include "params.h" | |
67 | #include "reload.h" | |
68 | #include "dwarf2asm.h" | |
69 | #include "integrate.h" | |
70 | #include "real.h" | |
71 | #include "debug.h" | |
72 | #include "target.h" | |
73 | #include "langhooks.h" | |
74 | #include "cfglayout.h" | |
75 | #include "cfgloop.h" | |
76 | #include "hosthooks.h" | |
77 | #include "cgraph.h" | |
78 | #include "opts.h" | |
79 | #include "coverage.h" | |
80 | #include "value-prof.h" | |
2f8e398b | 81 | #include "tree-pass.h" |
9f8628ba | 82 | #include "tree-dump.h" |
f6db1481 RH |
83 | |
84 | #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO) | |
85 | #include "dwarf2out.h" | |
86 | #endif | |
87 | ||
97b0ade3 | 88 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
f6db1481 RH |
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 | ||
9f8628ba | 110 | static int initializing_dump = 0; |
f6db1481 RH |
111 | |
112 | /* Routine to open a dump file. Return true if the dump file is enabled. */ | |
113 | ||
114 | static int | |
9f8628ba | 115 | open_dump_file (enum tree_dump_index index, tree decl) |
f6db1481 | 116 | { |
9f8628ba | 117 | if (! dump_enabled_p (index)) |
f6db1481 RH |
118 | return 0; |
119 | ||
120 | timevar_push (TV_DUMP); | |
f6db1481 | 121 | |
e16acfcd | 122 | gcc_assert (!dump_file && !dump_file_name); |
f6db1481 | 123 | |
9f8628ba PB |
124 | dump_file_name = get_dump_file_name (index); |
125 | initializing_dump = !dump_initialized_p (index); | |
126 | dump_file = dump_begin (index, NULL); | |
f6db1481 | 127 | |
f6db1481 | 128 | if (dump_file == NULL) |
9f8628ba | 129 | fatal_error ("can't open %s: %m", dump_file_name); |
f6db1481 RH |
130 | |
131 | if (decl) | |
132 | fprintf (dump_file, "\n;; Function %s%s\n\n", | |
ae2bcd98 | 133 | lang_hooks.decl_printable_name (decl, 2), |
f6db1481 RH |
134 | cfun->function_frequency == FUNCTION_FREQUENCY_HOT |
135 | ? " (hot)" | |
136 | : cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED | |
137 | ? " (unlikely executed)" | |
138 | : ""); | |
139 | ||
140 | timevar_pop (TV_DUMP); | |
141 | return 1; | |
142 | } | |
143 | ||
144 | /* Routine to close a dump file. */ | |
145 | ||
146 | static void | |
9f8628ba | 147 | close_dump_file (enum tree_dump_index index, |
f6db1481 RH |
148 | void (*func) (FILE *, rtx), |
149 | rtx insns) | |
150 | { | |
151 | if (! dump_file) | |
152 | return; | |
153 | ||
154 | timevar_push (TV_DUMP); | |
155 | if (insns | |
9f8628ba | 156 | && graph_dump_format != no_graph) |
f6db1481 | 157 | { |
9f8628ba PB |
158 | /* If we've not initialized the files, do so now. */ |
159 | if (initializing_dump) | |
160 | clean_graph_dump_file (dump_file_name); | |
f6db1481 | 161 | |
9f8628ba | 162 | print_rtl_graph_with_bb (dump_file_name, insns); |
f6db1481 RH |
163 | } |
164 | ||
165 | if (func && insns) | |
166 | func (dump_file, insns); | |
167 | ||
9f8628ba PB |
168 | dump_end (index, dump_file); |
169 | free ((char *) dump_file_name); | |
f6db1481 RH |
170 | |
171 | dump_file = NULL; | |
9f8628ba | 172 | dump_file_name = NULL; |
f6db1481 RH |
173 | timevar_pop (TV_DUMP); |
174 | } | |
175 | ||
176 | /* This is called from various places for FUNCTION_DECL, VAR_DECL, | |
177 | and TYPE_DECL nodes. | |
178 | ||
179 | This does nothing for local (non-static) variables, unless the | |
0e6df31e GK |
180 | variable is a register variable with DECL_ASSEMBLER_NAME set. In |
181 | that case, or if the variable is not an automatic, it sets up the | |
182 | RTL and outputs any assembler code (label definition, storage | |
183 | allocation and initialization). | |
f6db1481 | 184 | |
0e6df31e | 185 | DECL is the declaration. TOP_LEVEL is nonzero |
f6db1481 RH |
186 | if this declaration is not within a function. */ |
187 | ||
188 | void | |
189 | rest_of_decl_compilation (tree decl, | |
f6db1481 RH |
190 | int top_level, |
191 | int at_end) | |
192 | { | |
193 | /* We deferred calling assemble_alias so that we could collect | |
194 | other attributes such as visibility. Emit the alias now. */ | |
195 | { | |
196 | tree alias; | |
197 | alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)); | |
198 | if (alias) | |
199 | { | |
200 | alias = TREE_VALUE (TREE_VALUE (alias)); | |
201 | alias = get_identifier (TREE_STRING_POINTER (alias)); | |
202 | assemble_alias (decl, alias); | |
203 | } | |
204 | } | |
205 | ||
0e6df31e GK |
206 | /* Can't defer this, because it needs to happen before any |
207 | later function definitions are processed. */ | |
208 | if (DECL_REGISTER (decl) && DECL_ASSEMBLER_NAME_SET_P (decl)) | |
209 | make_decl_rtl (decl); | |
210 | ||
f6db1481 RH |
211 | /* Forward declarations for nested functions are not "external", |
212 | but we need to treat them as if they were. */ | |
213 | if (TREE_STATIC (decl) || DECL_EXTERNAL (decl) | |
214 | || TREE_CODE (decl) == FUNCTION_DECL) | |
215 | { | |
216 | timevar_push (TV_VARCONST); | |
217 | ||
f6db1481 RH |
218 | /* Don't output anything when a tentative file-scope definition |
219 | is seen. But at end of compilation, do output code for them. | |
220 | ||
221 | We do output all variables when unit-at-a-time is active and rely on | |
222 | callgraph code to defer them except for forward declarations | |
223 | (see gcc.c-torture/compile/920624-1.c) */ | |
224 | if ((at_end | |
225 | || !DECL_DEFER_OUTPUT (decl) | |
cd9c7bd2 | 226 | || DECL_INITIAL (decl)) |
f6db1481 RH |
227 | && !DECL_EXTERNAL (decl)) |
228 | { | |
229 | if (flag_unit_at_a_time && !cgraph_global_info_ready | |
30be951a | 230 | && TREE_CODE (decl) != FUNCTION_DECL) |
f6db1481 RH |
231 | cgraph_varpool_finalize_decl (decl); |
232 | else | |
233 | assemble_variable (decl, top_level, at_end, 0); | |
234 | } | |
235 | ||
236 | #ifdef ASM_FINISH_DECLARE_OBJECT | |
237 | if (decl == last_assemble_variable_decl) | |
238 | { | |
239 | ASM_FINISH_DECLARE_OBJECT (asm_out_file, decl, | |
240 | top_level, at_end); | |
241 | } | |
242 | #endif | |
243 | ||
244 | timevar_pop (TV_VARCONST); | |
245 | } | |
f6db1481 RH |
246 | else if (TREE_CODE (decl) == TYPE_DECL) |
247 | { | |
248 | timevar_push (TV_SYMOUT); | |
249 | debug_hooks->type_decl (decl, !top_level); | |
250 | timevar_pop (TV_SYMOUT); | |
251 | } | |
e4d5432a | 252 | |
aabcd309 | 253 | /* Let cgraph know about the existence of variables. */ |
e4d5432a RH |
254 | if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) |
255 | cgraph_varpool_node (decl); | |
f6db1481 RH |
256 | } |
257 | ||
258 | /* Called after finishing a record, union or enumeral type. */ | |
259 | ||
260 | void | |
261 | rest_of_type_compilation (tree type, int toplev) | |
262 | { | |
263 | /* Avoid confusing the debug information machinery when there are | |
264 | errors. */ | |
265 | if (errorcount != 0 || sorrycount != 0) | |
266 | return; | |
267 | ||
268 | timevar_push (TV_SYMOUT); | |
269 | debug_hooks->type_decl (TYPE_STUB_DECL (type), !toplev); | |
270 | timevar_pop (TV_SYMOUT); | |
271 | } | |
272 | ||
273 | /* Turn the RTL into assembly. */ | |
274 | static void | |
fd743bc1 | 275 | rest_of_handle_final (void) |
f6db1481 RH |
276 | { |
277 | timevar_push (TV_FINAL); | |
278 | { | |
279 | rtx x; | |
280 | const char *fnname; | |
281 | ||
282 | /* Get the function's name, as described by its RTL. This may be | |
283 | different from the DECL_NAME name used in the source file. */ | |
284 | ||
fd743bc1 | 285 | x = DECL_RTL (current_function_decl); |
e16acfcd | 286 | gcc_assert (MEM_P (x)); |
f6db1481 | 287 | x = XEXP (x, 0); |
e16acfcd | 288 | gcc_assert (GET_CODE (x) == SYMBOL_REF); |
f6db1481 RH |
289 | fnname = XSTR (x, 0); |
290 | ||
fd743bc1 PB |
291 | assemble_start_function (current_function_decl, fnname); |
292 | final_start_function (get_insns (), asm_out_file, optimize); | |
c9d691e9 | 293 | final (get_insns (), asm_out_file, optimize); |
f6db1481 RH |
294 | final_end_function (); |
295 | ||
951120ea | 296 | #ifdef TARGET_UNWIND_INFO |
f6db1481 RH |
297 | /* ??? The IA-64 ".handlerdata" directive must be issued before |
298 | the ".endp" directive that closes the procedure descriptor. */ | |
299 | output_function_exception_table (); | |
300 | #endif | |
301 | ||
fd743bc1 | 302 | assemble_end_function (current_function_decl, fnname); |
f6db1481 | 303 | |
951120ea | 304 | #ifndef TARGET_UNWIND_INFO |
f6db1481 RH |
305 | /* Otherwise, it feels unclean to switch sections in the middle. */ |
306 | output_function_exception_table (); | |
307 | #endif | |
308 | ||
9fb32434 CT |
309 | user_defined_section_attribute = false; |
310 | ||
f6db1481 RH |
311 | if (! quiet_flag) |
312 | fflush (asm_out_file); | |
313 | ||
314 | /* Release all memory allocated by flow. */ | |
bb8a619e | 315 | free_basic_block_vars (); |
f6db1481 | 316 | } |
97b0ade3 PB |
317 | |
318 | /* Write DBX symbols if requested. */ | |
319 | ||
320 | /* Note that for those inline functions where we don't initially | |
321 | know for certain that we will be generating an out-of-line copy, | |
322 | the first invocation of this routine (rest_of_compilation) will | |
323 | skip over this code by doing a `goto exit_rest_of_compilation;'. | |
324 | Later on, wrapup_global_declarations will (indirectly) call | |
325 | rest_of_compilation again for those inline functions that need | |
326 | to have out-of-line copies generated. During that call, we | |
327 | *will* be routed past here. */ | |
328 | ||
329 | timevar_push (TV_SYMOUT); | |
330 | (*debug_hooks->function_decl) (current_function_decl); | |
331 | timevar_pop (TV_SYMOUT); | |
f6db1481 RH |
332 | |
333 | ggc_collect (); | |
97b0ade3 | 334 | timevar_pop (TV_FINAL); |
f6db1481 RH |
335 | } |
336 | ||
337 | #ifdef DELAY_SLOTS | |
338 | /* Run delay slot optimization. */ | |
339 | static void | |
fd743bc1 | 340 | rest_of_handle_delay_slots (void) |
f6db1481 RH |
341 | { |
342 | timevar_push (TV_DBR_SCHED); | |
fd743bc1 | 343 | open_dump_file (DFI_dbr, current_function_decl); |
f6db1481 | 344 | |
fd743bc1 | 345 | dbr_schedule (get_insns (), dump_file); |
f6db1481 | 346 | |
fd743bc1 | 347 | close_dump_file (DFI_dbr, print_rtl, get_insns ()); |
f6db1481 RH |
348 | |
349 | ggc_collect (); | |
97b0ade3 PB |
350 | |
351 | timevar_pop (TV_DBR_SCHED); | |
f6db1481 RH |
352 | } |
353 | #endif | |
354 | ||
355 | #ifdef STACK_REGS | |
356 | /* Convert register usage from flat register file usage to a stack | |
357 | register file. */ | |
358 | static void | |
fd743bc1 | 359 | rest_of_handle_stack_regs (void) |
f6db1481 RH |
360 | { |
361 | #if defined (HAVE_ATTR_length) | |
362 | /* If flow2 creates new instructions which need splitting | |
363 | and scheduling after reload is not done, they might not be | |
364 | split until final which doesn't allow splitting | |
365 | if HAVE_ATTR_length. */ | |
366 | #ifdef INSN_SCHEDULING | |
367 | if (optimize && !flag_schedule_insns_after_reload) | |
368 | #else | |
369 | if (optimize) | |
370 | #endif | |
371 | { | |
372 | timevar_push (TV_SHORTEN_BRANCH); | |
373 | split_all_insns (1); | |
374 | timevar_pop (TV_SHORTEN_BRANCH); | |
375 | } | |
376 | #endif | |
377 | ||
378 | timevar_push (TV_REG_STACK); | |
fd743bc1 | 379 | open_dump_file (DFI_stack, current_function_decl); |
f6db1481 | 380 | |
827c06b6 | 381 | if (reg_to_stack (dump_file) && optimize) |
f6db1481 RH |
382 | { |
383 | if (cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK | |
384 | | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0)) | |
750054a2 | 385 | && (flag_reorder_blocks || flag_reorder_blocks_and_partition)) |
f6db1481 | 386 | { |
35b6b437 | 387 | reorder_basic_blocks (0); |
f6db1481 RH |
388 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_POST_REGSTACK); |
389 | } | |
390 | } | |
391 | ||
fd743bc1 | 392 | close_dump_file (DFI_stack, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
393 | |
394 | ggc_collect (); | |
97b0ade3 | 395 | timevar_pop (TV_REG_STACK); |
f6db1481 RH |
396 | } |
397 | #endif | |
398 | ||
89dbed81 | 399 | /* Track the variables, i.e. compute where the variable is stored at each position in function. */ |
f6db1481 | 400 | static void |
fd743bc1 | 401 | rest_of_handle_variable_tracking (void) |
f6db1481 RH |
402 | { |
403 | timevar_push (TV_VAR_TRACKING); | |
fd743bc1 | 404 | open_dump_file (DFI_vartrack, current_function_decl); |
f6db1481 RH |
405 | |
406 | variable_tracking_main (); | |
407 | ||
fd743bc1 | 408 | close_dump_file (DFI_vartrack, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
409 | timevar_pop (TV_VAR_TRACKING); |
410 | } | |
411 | ||
97b0ade3 | 412 | /* Machine dependent reorg pass. */ |
f6db1481 | 413 | static void |
fd743bc1 | 414 | rest_of_handle_machine_reorg (void) |
f6db1481 RH |
415 | { |
416 | timevar_push (TV_MACH_DEP); | |
fd743bc1 | 417 | open_dump_file (DFI_mach, current_function_decl); |
f6db1481 | 418 | |
5fd9b178 | 419 | targetm.machine_dependent_reorg (); |
f6db1481 | 420 | |
fd743bc1 | 421 | close_dump_file (DFI_mach, print_rtl, get_insns ()); |
f6db1481 RH |
422 | |
423 | ggc_collect (); | |
97b0ade3 | 424 | timevar_pop (TV_MACH_DEP); |
f6db1481 RH |
425 | } |
426 | ||
427 | ||
f6db1481 RH |
428 | /* Run old register allocator. Return TRUE if we must exit |
429 | rest_of_compilation upon return. */ | |
430 | static bool | |
fd743bc1 | 431 | rest_of_handle_old_regalloc (void) |
f6db1481 RH |
432 | { |
433 | int failure; | |
434 | int rebuild_notes; | |
435 | ||
97b0ade3 PB |
436 | timevar_push (TV_LOCAL_ALLOC); |
437 | open_dump_file (DFI_lreg, current_function_decl); | |
438 | ||
f6db1481 RH |
439 | /* Allocate the reg_renumber array. */ |
440 | allocate_reg_info (max_regno, FALSE, TRUE); | |
441 | ||
442 | /* And the reg_equiv_memory_loc array. */ | |
965ccc5a R |
443 | VARRAY_GROW (reg_equiv_memory_loc_varray, max_regno); |
444 | reg_equiv_memory_loc = &VARRAY_RTX (reg_equiv_memory_loc_varray, 0); | |
f6db1481 RH |
445 | |
446 | allocate_initial_values (reg_equiv_memory_loc); | |
447 | ||
fd743bc1 | 448 | regclass (get_insns (), max_reg_num (), dump_file); |
f6db1481 RH |
449 | rebuild_notes = local_alloc (); |
450 | ||
451 | timevar_pop (TV_LOCAL_ALLOC); | |
452 | ||
453 | /* Local allocation may have turned an indirect jump into a direct | |
454 | jump. If so, we must rebuild the JUMP_LABEL fields of jumping | |
455 | instructions. */ | |
456 | if (rebuild_notes) | |
457 | { | |
458 | timevar_push (TV_JUMP); | |
459 | ||
fd743bc1 | 460 | rebuild_jump_labels (get_insns ()); |
25cd19de | 461 | purge_all_dead_edges (); |
9b09c842 | 462 | delete_unreachable_blocks (); |
f6db1481 RH |
463 | |
464 | timevar_pop (TV_JUMP); | |
465 | } | |
466 | ||
9f8628ba | 467 | if (dump_enabled_p (DFI_lreg)) |
f6db1481 RH |
468 | { |
469 | timevar_push (TV_DUMP); | |
f6db1481 RH |
470 | dump_flow_info (dump_file); |
471 | dump_local_alloc (dump_file); | |
f6db1481 RH |
472 | timevar_pop (TV_DUMP); |
473 | } | |
474 | ||
97b0ade3 PB |
475 | close_dump_file (DFI_lreg, print_rtl_with_bb, get_insns ()); |
476 | ||
f6db1481 RH |
477 | ggc_collect (); |
478 | ||
479 | timevar_push (TV_GLOBAL_ALLOC); | |
fd743bc1 | 480 | open_dump_file (DFI_greg, current_function_decl); |
f6db1481 RH |
481 | |
482 | /* If optimizing, allocate remaining pseudo-regs. Do the reload | |
483 | pass fixing up any insns that are invalid. */ | |
484 | ||
485 | if (optimize) | |
486 | failure = global_alloc (dump_file); | |
487 | else | |
488 | { | |
fd743bc1 PB |
489 | build_insn_chain (get_insns ()); |
490 | failure = reload (get_insns (), 0); | |
f6db1481 RH |
491 | } |
492 | ||
9f8628ba | 493 | if (dump_enabled_p (DFI_greg)) |
f6db1481 RH |
494 | { |
495 | timevar_push (TV_DUMP); | |
f6db1481 | 496 | dump_global_regs (dump_file); |
97b0ade3 | 497 | timevar_pop (TV_DUMP); |
f6db1481 | 498 | |
fd743bc1 | 499 | close_dump_file (DFI_greg, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
500 | } |
501 | ||
97b0ade3 PB |
502 | ggc_collect (); |
503 | ||
504 | timevar_pop (TV_GLOBAL_ALLOC); | |
505 | ||
f6db1481 RH |
506 | return failure; |
507 | } | |
508 | ||
509 | /* Run the regrename and cprop passes. */ | |
510 | static void | |
fd743bc1 | 511 | rest_of_handle_regrename (void) |
f6db1481 RH |
512 | { |
513 | timevar_push (TV_RENAME_REGISTERS); | |
fd743bc1 | 514 | open_dump_file (DFI_rnreg, current_function_decl); |
f6db1481 RH |
515 | |
516 | if (flag_rename_registers) | |
517 | regrename_optimize (); | |
518 | if (flag_cprop_registers) | |
519 | copyprop_hardreg_forward (); | |
520 | ||
fd743bc1 | 521 | close_dump_file (DFI_rnreg, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
522 | timevar_pop (TV_RENAME_REGISTERS); |
523 | } | |
524 | ||
525 | /* Reorder basic blocks. */ | |
526 | static void | |
fd743bc1 | 527 | rest_of_handle_reorder_blocks (void) |
f6db1481 RH |
528 | { |
529 | bool changed; | |
35b6b437 RS |
530 | unsigned int liveness_flags; |
531 | ||
fd743bc1 | 532 | open_dump_file (DFI_bbro, current_function_decl); |
2f8e398b | 533 | |
f6db1481 RH |
534 | /* Last attempt to optimize CFG, as scheduling, peepholing and insn |
535 | splitting possibly introduced more crossjumping opportunities. */ | |
35b6b437 RS |
536 | liveness_flags = (!HAVE_conditional_execution ? CLEANUP_UPDATE_LIFE : 0); |
537 | changed = cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags); | |
f6db1481 RH |
538 | |
539 | if (flag_sched2_use_traces && flag_schedule_insns_after_reload) | |
35b6b437 | 540 | tracer (liveness_flags); |
750054a2 | 541 | if (flag_reorder_blocks || flag_reorder_blocks_and_partition) |
35b6b437 | 542 | reorder_basic_blocks (liveness_flags); |
750054a2 | 543 | if (flag_reorder_blocks || flag_reorder_blocks_and_partition |
f6db1481 | 544 | || (flag_sched2_use_traces && flag_schedule_insns_after_reload)) |
35b6b437 | 545 | changed |= cleanup_cfg (CLEANUP_EXPENSIVE | liveness_flags); |
f6db1481 RH |
546 | |
547 | /* On conditional execution targets we can not update the life cheaply, so | |
548 | we deffer the updating to after both cleanups. This may lose some cases | |
549 | but should not be terribly bad. */ | |
550 | if (changed && HAVE_conditional_execution) | |
551 | update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES, | |
552 | PROP_DEATH_NOTES); | |
fd743bc1 | 553 | close_dump_file (DFI_bbro, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
554 | } |
555 | ||
97b0ade3 PB |
556 | /* Partition hot and cold basic blocks. */ |
557 | static void | |
558 | rest_of_handle_partition_blocks (void) | |
559 | { | |
560 | no_new_pseudos = 0; | |
561 | partition_hot_cold_basic_blocks (); | |
562 | allocate_reg_life_data (); | |
563 | update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES, | |
564 | PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES); | |
565 | no_new_pseudos = 1; | |
566 | } | |
567 | ||
f6db1481 RH |
568 | #ifdef INSN_SCHEDULING |
569 | /* Run instruction scheduler. */ | |
97b0ade3 | 570 | /* Perform SMS module scheduling. */ |
f6db1481 | 571 | static void |
97b0ade3 | 572 | rest_of_handle_sms (void) |
f6db1481 | 573 | { |
f73d5666 | 574 | basic_block bb; |
d331e204 MH |
575 | sbitmap blocks; |
576 | ||
e5626198 | 577 | timevar_push (TV_SMS); |
97b0ade3 | 578 | open_dump_file (DFI_sms, current_function_decl); |
e5626198 | 579 | |
97b0ade3 PB |
580 | /* We want to be able to create new pseudos. */ |
581 | no_new_pseudos = 0; | |
f73d5666 MH |
582 | /* Collect loop information to be used in SMS. */ |
583 | cfg_layout_initialize (CLEANUP_UPDATE_LIFE); | |
97b0ade3 PB |
584 | sms_schedule (dump_file); |
585 | close_dump_file (DFI_sms, print_rtl, get_insns ()); | |
e5626198 | 586 | |
97b0ade3 PB |
587 | /* Update the life information, because we add pseudos. */ |
588 | max_regno = max_reg_num (); | |
589 | allocate_reg_info (max_regno, FALSE, FALSE); | |
d331e204 MH |
590 | blocks = sbitmap_alloc (last_basic_block); |
591 | sbitmap_ones (blocks); | |
592 | update_life_info (blocks, UPDATE_LIFE_GLOBAL_RM_NOTES, | |
593 | (PROP_DEATH_NOTES | |
594 | | PROP_REG_INFO | |
595 | | PROP_KILL_DEAD_CODE | |
596 | | PROP_SCAN_DEAD_CODE)); | |
597 | ||
97b0ade3 | 598 | no_new_pseudos = 1; |
e5626198 | 599 | |
f73d5666 MH |
600 | /* Finalize layout changes. */ |
601 | FOR_EACH_BB (bb) | |
602 | if (bb->next_bb != EXIT_BLOCK_PTR) | |
370369e1 | 603 | bb->aux = bb->next_bb; |
f73d5666 MH |
604 | cfg_layout_finalize (); |
605 | free_dominance_info (CDI_DOMINATORS); | |
97b0ade3 | 606 | ggc_collect (); |
e5626198 | 607 | timevar_pop (TV_SMS); |
97b0ade3 PB |
608 | } |
609 | ||
610 | /* Run instruction scheduler. */ | |
611 | static void | |
612 | rest_of_handle_sched (void) | |
613 | { | |
f6db1481 RH |
614 | timevar_push (TV_SCHED); |
615 | ||
616 | /* Print function header into sched dump now | |
617 | because doing the sched analysis makes some of the dump. */ | |
97b0ade3 | 618 | open_dump_file (DFI_sched, current_function_decl); |
f6db1481 | 619 | |
97b0ade3 PB |
620 | /* Do control and data sched analysis, |
621 | and write some of the results to dump file. */ | |
f6db1481 | 622 | |
97b0ade3 | 623 | schedule_insns (dump_file); |
f6db1481 | 624 | |
97b0ade3 | 625 | close_dump_file (DFI_sched, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
626 | |
627 | ggc_collect (); | |
97b0ade3 | 628 | timevar_pop (TV_SCHED); |
f6db1481 RH |
629 | } |
630 | ||
631 | /* Run second scheduling pass after reload. */ | |
632 | static void | |
fd743bc1 | 633 | rest_of_handle_sched2 (void) |
f6db1481 RH |
634 | { |
635 | timevar_push (TV_SCHED2); | |
fd743bc1 | 636 | open_dump_file (DFI_sched2, current_function_decl); |
f6db1481 RH |
637 | |
638 | /* Do control and data sched analysis again, | |
639 | and write some more of the results to dump file. */ | |
640 | ||
641 | split_all_insns (1); | |
642 | ||
643 | if (flag_sched2_use_superblocks || flag_sched2_use_traces) | |
644 | { | |
645 | schedule_ebbs (dump_file); | |
646 | /* No liveness updating code yet, but it should be easy to do. | |
4ee31f1e | 647 | reg-stack recomputes the liveness when needed for now. */ |
f6db1481 RH |
648 | count_or_remove_death_notes (NULL, 1); |
649 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
650 | } | |
651 | else | |
652 | schedule_insns (dump_file); | |
653 | ||
fd743bc1 | 654 | close_dump_file (DFI_sched2, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
655 | |
656 | ggc_collect (); | |
97b0ade3 PB |
657 | |
658 | timevar_pop (TV_SCHED2); | |
f6db1481 RH |
659 | } |
660 | #endif | |
661 | ||
f9957958 | 662 | static void |
fd743bc1 | 663 | rest_of_handle_gcse2 (void) |
f9957958 | 664 | { |
0516f6fe | 665 | timevar_push (TV_GCSE_AFTER_RELOAD); |
fd743bc1 | 666 | open_dump_file (DFI_gcse2, current_function_decl); |
f9957958 | 667 | |
0516f6fe | 668 | gcse_after_reload_main (get_insns ()); |
fd743bc1 PB |
669 | rebuild_jump_labels (get_insns ()); |
670 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); | |
671 | close_dump_file (DFI_gcse2, print_rtl_with_bb, get_insns ()); | |
f9957958 MH |
672 | |
673 | ggc_collect (); | |
674 | ||
675 | #ifdef ENABLE_CHECKING | |
676 | verify_flow_info (); | |
677 | #endif | |
97b0ade3 | 678 | |
0516f6fe | 679 | timevar_pop (TV_GCSE_AFTER_RELOAD); |
f9957958 MH |
680 | } |
681 | ||
f6db1481 RH |
682 | /* Register allocation pre-pass, to reduce number of moves necessary |
683 | for two-address machines. */ | |
684 | static void | |
fd743bc1 | 685 | rest_of_handle_regmove (void) |
f6db1481 RH |
686 | { |
687 | timevar_push (TV_REGMOVE); | |
fd743bc1 | 688 | open_dump_file (DFI_regmove, current_function_decl); |
f6db1481 | 689 | |
fd743bc1 | 690 | regmove_optimize (get_insns (), max_reg_num (), dump_file); |
f6db1481 RH |
691 | |
692 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE); | |
fd743bc1 | 693 | close_dump_file (DFI_regmove, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
694 | |
695 | ggc_collect (); | |
97b0ade3 | 696 | timevar_pop (TV_REGMOVE); |
f6db1481 RH |
697 | } |
698 | ||
699 | /* Run tracer. */ | |
700 | static void | |
fd743bc1 | 701 | rest_of_handle_tracer (void) |
f6db1481 | 702 | { |
fd743bc1 | 703 | open_dump_file (DFI_tracer, current_function_decl); |
f6db1481 RH |
704 | if (dump_file) |
705 | dump_flow_info (dump_file); | |
35b6b437 | 706 | tracer (0); |
f6db1481 | 707 | cleanup_cfg (CLEANUP_EXPENSIVE); |
c80a0f26 | 708 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 RH |
709 | close_dump_file (DFI_tracer, print_rtl_with_bb, get_insns ()); |
710 | } | |
711 | ||
712 | /* If-conversion and CFG cleanup. */ | |
713 | static void | |
fd743bc1 | 714 | rest_of_handle_if_conversion (void) |
f6db1481 | 715 | { |
97b0ade3 | 716 | timevar_push (TV_IFCVT); |
fd743bc1 | 717 | open_dump_file (DFI_ce1, current_function_decl); |
97b0ade3 | 718 | |
f6db1481 RH |
719 | if (flag_if_conversion) |
720 | { | |
f6db1481 RH |
721 | if (dump_file) |
722 | dump_flow_info (dump_file); | |
723 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
c80a0f26 | 724 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 | 725 | if_convert (0); |
f6db1481 | 726 | } |
97b0ade3 | 727 | |
f6db1481 RH |
728 | timevar_push (TV_JUMP); |
729 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
c80a0f26 | 730 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 | 731 | timevar_pop (TV_JUMP); |
97b0ade3 | 732 | |
f6db1481 | 733 | close_dump_file (DFI_ce1, print_rtl_with_bb, get_insns ()); |
97b0ade3 | 734 | timevar_pop (TV_IFCVT); |
f6db1481 RH |
735 | } |
736 | ||
737 | /* Rerun if-conversion, as combine may have simplified things enough | |
738 | to now meet sequence length restrictions. */ | |
739 | static void | |
fd743bc1 | 740 | rest_of_handle_if_after_combine (void) |
f6db1481 RH |
741 | { |
742 | timevar_push (TV_IFCVT); | |
fd743bc1 | 743 | open_dump_file (DFI_ce2, current_function_decl); |
f6db1481 RH |
744 | |
745 | no_new_pseudos = 0; | |
746 | if_convert (1); | |
747 | no_new_pseudos = 1; | |
748 | ||
fd743bc1 | 749 | close_dump_file (DFI_ce2, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
750 | timevar_pop (TV_IFCVT); |
751 | } | |
752 | ||
97b0ade3 PB |
753 | static void |
754 | rest_of_handle_if_after_reload (void) | |
755 | { | |
756 | timevar_push (TV_IFCVT2); | |
757 | open_dump_file (DFI_ce3, current_function_decl); | |
758 | ||
759 | /* Last attempt to optimize CFG, as scheduling, peepholing and insn | |
760 | splitting possibly introduced more crossjumping opportunities. */ | |
761 | cleanup_cfg (CLEANUP_EXPENSIVE | |
762 | | CLEANUP_UPDATE_LIFE | |
763 | | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0)); | |
764 | if (flag_if_conversion2) | |
765 | if_convert (1); | |
766 | close_dump_file (DFI_ce3, print_rtl_with_bb, get_insns ()); | |
767 | timevar_pop (TV_IFCVT2); | |
768 | } | |
769 | ||
f6db1481 | 770 | static void |
fd743bc1 | 771 | rest_of_handle_web (void) |
f6db1481 | 772 | { |
fd743bc1 | 773 | open_dump_file (DFI_web, current_function_decl); |
f6db1481 RH |
774 | timevar_push (TV_WEB); |
775 | web_main (); | |
fd743bc1 | 776 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
f6db1481 RH |
777 | cleanup_cfg (CLEANUP_EXPENSIVE); |
778 | ||
779 | timevar_pop (TV_WEB); | |
fd743bc1 | 780 | close_dump_file (DFI_web, print_rtl_with_bb, get_insns ()); |
c80a0f26 | 781 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 RH |
782 | } |
783 | ||
784 | /* Do branch profiling and static profile estimation passes. */ | |
785 | static void | |
fd743bc1 | 786 | rest_of_handle_branch_prob (void) |
f6db1481 RH |
787 | { |
788 | struct loops loops; | |
97b0ade3 | 789 | |
f6db1481 | 790 | timevar_push (TV_BRANCH_PROB); |
fd743bc1 | 791 | open_dump_file (DFI_bp, current_function_decl); |
f6db1481 | 792 | |
5d9f607b JH |
793 | if ((profile_arc_flag || flag_test_coverage || flag_branch_probabilities) |
794 | && !flag_tree_based_profiling) | |
f6db1481 RH |
795 | branch_prob (); |
796 | ||
797 | /* Discover and record the loop depth at the head of each basic | |
798 | block. The loop infrastructure does the real job for us. */ | |
70388d94 | 799 | flow_loops_find (&loops); |
f6db1481 RH |
800 | |
801 | if (dump_file) | |
802 | flow_loops_dump (&loops, dump_file, NULL, 0); | |
803 | ||
804 | /* Estimate using heuristics if no profiling info is available. */ | |
5d9f607b | 805 | if (flag_guess_branch_prob && profile_status == PROFILE_ABSENT) |
f6db1481 RH |
806 | estimate_probability (&loops); |
807 | ||
808 | flow_loops_free (&loops); | |
809 | free_dominance_info (CDI_DOMINATORS); | |
fd743bc1 | 810 | close_dump_file (DFI_bp, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
811 | timevar_pop (TV_BRANCH_PROB); |
812 | } | |
813 | ||
814 | /* Do optimizations based on expression value profiles. */ | |
815 | static void | |
fd743bc1 | 816 | rest_of_handle_value_profile_transformations (void) |
f6db1481 | 817 | { |
fd743bc1 | 818 | open_dump_file (DFI_vpt, current_function_decl); |
f6db1481 RH |
819 | timevar_push (TV_VPT); |
820 | ||
821 | if (value_profile_transformations ()) | |
822 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
823 | ||
824 | timevar_pop (TV_VPT); | |
fd743bc1 | 825 | close_dump_file (DFI_vpt, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
826 | } |
827 | ||
828 | /* Do control and data flow analysis; write some of the results to the | |
829 | dump file. */ | |
830 | static void | |
fd743bc1 | 831 | rest_of_handle_cfg (void) |
f6db1481 | 832 | { |
fd743bc1 | 833 | open_dump_file (DFI_cfg, current_function_decl); |
f6db1481 RH |
834 | if (dump_file) |
835 | dump_flow_info (dump_file); | |
836 | if (optimize) | |
837 | cleanup_cfg (CLEANUP_EXPENSIVE | |
838 | | (flag_thread_jumps ? CLEANUP_THREADING : 0)); | |
839 | ||
840 | /* It may make more sense to mark constant functions after dead code is | |
841 | eliminated by life_analysis, but we need to do it early, as -fprofile-arcs | |
842 | may insert code making function non-constant, but we still must consider | |
843 | it as constant, otherwise -fbranch-probabilities will not read data back. | |
844 | ||
845 | life_analysis rarely eliminates modification of external memory. | |
70f3cc30 JH |
846 | |
847 | FIXME: now with tree based profiling we are in the trap described above | |
848 | again. It seems to be easiest to disable the optimization for time | |
849 | being before the problem is either solved by moving the transformation | |
850 | to the IPA level (we need the CFG for this) or the very early optimization | |
851 | passes are made to ignore the const/pure flags so code does not change. */ | |
852 | if (optimize | |
853 | && (!flag_tree_based_profiling | |
854 | || (!profile_arc_flag && !flag_branch_probabilities))) | |
f6db1481 RH |
855 | { |
856 | /* Alias analysis depends on this information and mark_constant_function | |
857 | depends on alias analysis. */ | |
c80a0f26 | 858 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 RH |
859 | mark_constant_function (); |
860 | } | |
861 | ||
fd743bc1 | 862 | close_dump_file (DFI_cfg, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
863 | } |
864 | ||
f6db1481 RH |
865 | /* Perform jump bypassing and control flow optimizations. */ |
866 | static void | |
fd743bc1 | 867 | rest_of_handle_jump_bypass (void) |
f6db1481 RH |
868 | { |
869 | timevar_push (TV_BYPASS); | |
fd743bc1 | 870 | open_dump_file (DFI_bypass, current_function_decl); |
f6db1481 RH |
871 | |
872 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
c80a0f26 | 873 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 RH |
874 | |
875 | if (bypass_jumps (dump_file)) | |
876 | { | |
fd743bc1 | 877 | rebuild_jump_labels (get_insns ()); |
f6db1481 | 878 | cleanup_cfg (CLEANUP_EXPENSIVE); |
fd743bc1 | 879 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
f6db1481 RH |
880 | } |
881 | ||
fd743bc1 | 882 | close_dump_file (DFI_bypass, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
883 | timevar_pop (TV_BYPASS); |
884 | ||
885 | ggc_collect (); | |
886 | ||
887 | #ifdef ENABLE_CHECKING | |
888 | verify_flow_info (); | |
889 | #endif | |
890 | } | |
891 | ||
f6db1481 RH |
892 | /* Try combining insns through substitution. */ |
893 | static void | |
fd743bc1 | 894 | rest_of_handle_combine (void) |
f6db1481 RH |
895 | { |
896 | int rebuild_jump_labels_after_combine = 0; | |
897 | ||
898 | timevar_push (TV_COMBINE); | |
fd743bc1 | 899 | open_dump_file (DFI_combine, current_function_decl); |
f6db1481 RH |
900 | |
901 | rebuild_jump_labels_after_combine | |
fd743bc1 | 902 | = combine_instructions (get_insns (), max_reg_num ()); |
f6db1481 | 903 | |
97b0ade3 | 904 | /* Combining insns may have turned an indirect jump into a |
f6db1481 RH |
905 | direct jump. Rebuild the JUMP_LABEL fields of jumping |
906 | instructions. */ | |
907 | if (rebuild_jump_labels_after_combine) | |
908 | { | |
909 | timevar_push (TV_JUMP); | |
fd743bc1 | 910 | rebuild_jump_labels (get_insns ()); |
f6db1481 RH |
911 | timevar_pop (TV_JUMP); |
912 | ||
78d5a34b | 913 | delete_dead_jumptables (); |
f6db1481 RH |
914 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE); |
915 | } | |
916 | ||
fd743bc1 | 917 | close_dump_file (DFI_combine, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
918 | timevar_pop (TV_COMBINE); |
919 | ||
920 | ggc_collect (); | |
921 | } | |
922 | ||
923 | /* Perform life analysis. */ | |
924 | static void | |
fd743bc1 | 925 | rest_of_handle_life (void) |
f6db1481 | 926 | { |
fd743bc1 | 927 | open_dump_file (DFI_life, current_function_decl); |
f6db1481 RH |
928 | regclass_init (); |
929 | ||
930 | #ifdef ENABLE_CHECKING | |
931 | verify_flow_info (); | |
932 | #endif | |
827c06b6 | 933 | life_analysis (dump_file, PROP_FINAL); |
f6db1481 | 934 | if (optimize) |
c80a0f26 | 935 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE | CLEANUP_LOG_LINKS |
f6db1481 | 936 | | (flag_thread_jumps ? CLEANUP_THREADING : 0)); |
f6db1481 | 937 | |
6de9cd9a | 938 | if (extra_warnings) |
f6db1481 | 939 | { |
fd743bc1 | 940 | setjmp_vars_warning (DECL_INITIAL (current_function_decl)); |
6de9cd9a | 941 | setjmp_args_warning (); |
f6db1481 RH |
942 | } |
943 | ||
944 | if (optimize) | |
945 | { | |
cd280abb | 946 | if (initialize_uninitialized_subregs ()) |
f6db1481 RH |
947 | { |
948 | /* Insns were inserted, and possibly pseudos created, so | |
949 | things might look a bit different. */ | |
f6db1481 RH |
950 | allocate_reg_life_data (); |
951 | update_life_info (NULL, UPDATE_LIFE_GLOBAL_RM_NOTES, | |
952 | PROP_LOG_LINKS | PROP_REG_INFO | PROP_DEATH_NOTES); | |
953 | } | |
954 | } | |
955 | ||
956 | no_new_pseudos = 1; | |
957 | ||
fd743bc1 | 958 | close_dump_file (DFI_life, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
959 | |
960 | ggc_collect (); | |
961 | } | |
962 | ||
963 | /* Perform common subexpression elimination. Nonzero value from | |
964 | `cse_main' means that jumps were simplified and some code may now | |
965 | be unreachable, so do jump optimization again. */ | |
966 | static void | |
fd743bc1 | 967 | rest_of_handle_cse (void) |
f6db1481 RH |
968 | { |
969 | int tem; | |
97b0ade3 | 970 | |
fd743bc1 | 971 | open_dump_file (DFI_cse, current_function_decl); |
f6db1481 RH |
972 | if (dump_file) |
973 | dump_flow_info (dump_file); | |
974 | timevar_push (TV_CSE); | |
975 | ||
c80a0f26 | 976 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 | 977 | |
5affca01 | 978 | tem = cse_main (get_insns (), max_reg_num (), dump_file); |
f6db1481 | 979 | if (tem) |
fd743bc1 | 980 | rebuild_jump_labels (get_insns ()); |
25cd19de | 981 | if (purge_all_dead_edges ()) |
f6db1481 RH |
982 | delete_unreachable_blocks (); |
983 | ||
fd743bc1 | 984 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
f6db1481 RH |
985 | |
986 | /* If we are not running more CSE passes, then we are no longer | |
987 | expecting CSE to be run. But always rerun it in a cheap mode. */ | |
988 | cse_not_expected = !flag_rerun_cse_after_loop && !flag_gcse; | |
989 | ||
78d5a34b KH |
990 | if (tem) |
991 | delete_dead_jumptables (); | |
992 | ||
f6db1481 RH |
993 | if (tem || optimize > 1) |
994 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
f6db1481 RH |
995 | |
996 | timevar_pop (TV_CSE); | |
fd743bc1 | 997 | close_dump_file (DFI_cse, print_rtl_with_bb, get_insns ()); |
97b0ade3 PB |
998 | |
999 | ggc_collect (); | |
f6db1481 RH |
1000 | } |
1001 | ||
1002 | /* Run second CSE pass after loop optimizations. */ | |
1003 | static void | |
fd743bc1 | 1004 | rest_of_handle_cse2 (void) |
f6db1481 RH |
1005 | { |
1006 | int tem; | |
97b0ade3 | 1007 | |
f6db1481 | 1008 | timevar_push (TV_CSE2); |
fd743bc1 | 1009 | open_dump_file (DFI_cse2, current_function_decl); |
f6db1481 RH |
1010 | if (dump_file) |
1011 | dump_flow_info (dump_file); | |
c2f7fa15 | 1012 | |
5affca01 | 1013 | tem = cse_main (get_insns (), max_reg_num (), dump_file); |
f6db1481 RH |
1014 | |
1015 | /* Run a pass to eliminate duplicated assignments to condition code | |
1016 | registers. We have to run this after bypass_jumps, because it | |
1017 | makes it harder for that pass to determine whether a jump can be | |
1018 | bypassed safely. */ | |
1019 | cse_condition_code_reg (); | |
1020 | ||
25cd19de | 1021 | purge_all_dead_edges (); |
fd743bc1 | 1022 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
f6db1481 RH |
1023 | |
1024 | if (tem) | |
1025 | { | |
1026 | timevar_push (TV_JUMP); | |
fd743bc1 | 1027 | rebuild_jump_labels (get_insns ()); |
78d5a34b | 1028 | delete_dead_jumptables (); |
f6db1481 RH |
1029 | cleanup_cfg (CLEANUP_EXPENSIVE); |
1030 | timevar_pop (TV_JUMP); | |
1031 | } | |
c80a0f26 | 1032 | reg_scan (get_insns (), max_reg_num ()); |
fd743bc1 | 1033 | close_dump_file (DFI_cse2, print_rtl_with_bb, get_insns ()); |
f6db1481 | 1034 | timevar_pop (TV_CSE2); |
97b0ade3 PB |
1035 | |
1036 | ggc_collect (); | |
f6db1481 RH |
1037 | } |
1038 | ||
1039 | /* Perform global cse. */ | |
1040 | static void | |
fd743bc1 | 1041 | rest_of_handle_gcse (void) |
f6db1481 RH |
1042 | { |
1043 | int save_csb, save_cfj; | |
1044 | int tem2 = 0, tem; | |
97b0ade3 | 1045 | |
f6db1481 | 1046 | timevar_push (TV_GCSE); |
fd743bc1 | 1047 | open_dump_file (DFI_gcse, current_function_decl); |
f6db1481 | 1048 | |
fd743bc1 PB |
1049 | tem = gcse_main (get_insns (), dump_file); |
1050 | rebuild_jump_labels (get_insns ()); | |
1051 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); | |
f6db1481 RH |
1052 | |
1053 | save_csb = flag_cse_skip_blocks; | |
1054 | save_cfj = flag_cse_follow_jumps; | |
1055 | flag_cse_skip_blocks = flag_cse_follow_jumps = 0; | |
1056 | ||
f6db1481 RH |
1057 | /* If -fexpensive-optimizations, re-run CSE to clean up things done |
1058 | by gcse. */ | |
1059 | if (flag_expensive_optimizations) | |
1060 | { | |
1061 | timevar_push (TV_CSE); | |
c80a0f26 | 1062 | reg_scan (get_insns (), max_reg_num ()); |
5affca01 | 1063 | tem2 = cse_main (get_insns (), max_reg_num (), dump_file); |
25cd19de | 1064 | purge_all_dead_edges (); |
fd743bc1 | 1065 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
f6db1481 RH |
1066 | timevar_pop (TV_CSE); |
1067 | cse_not_expected = !flag_rerun_cse_after_loop; | |
1068 | } | |
1069 | ||
1070 | /* If gcse or cse altered any jumps, rerun jump optimizations to clean | |
83cc36c8 | 1071 | things up. */ |
6f9087d7 | 1072 | if (tem || tem2) |
f6db1481 | 1073 | { |
f6db1481 | 1074 | timevar_push (TV_JUMP); |
fd743bc1 | 1075 | rebuild_jump_labels (get_insns ()); |
78d5a34b | 1076 | delete_dead_jumptables (); |
f6db1481 RH |
1077 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); |
1078 | timevar_pop (TV_JUMP); | |
f6db1481 RH |
1079 | } |
1080 | ||
fd743bc1 | 1081 | close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ()); |
f6db1481 RH |
1082 | timevar_pop (TV_GCSE); |
1083 | ||
1084 | ggc_collect (); | |
1085 | flag_cse_skip_blocks = save_csb; | |
1086 | flag_cse_follow_jumps = save_cfj; | |
1087 | #ifdef ENABLE_CHECKING | |
1088 | verify_flow_info (); | |
1089 | #endif | |
1090 | } | |
1091 | ||
1092 | /* Move constant computations out of loops. */ | |
1093 | static void | |
fd743bc1 | 1094 | rest_of_handle_loop_optimize (void) |
f6db1481 | 1095 | { |
c94583fe | 1096 | int do_prefetch; |
f6db1481 RH |
1097 | |
1098 | timevar_push (TV_LOOP); | |
fd743bc1 | 1099 | open_dump_file (DFI_loop, current_function_decl); |
f6db1481 RH |
1100 | |
1101 | /* CFG is no longer maintained up-to-date. */ | |
1102 | free_bb_for_insn (); | |
e53de54d | 1103 | profile_status = PROFILE_ABSENT; |
f6db1481 | 1104 | |
f6db1481 RH |
1105 | do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0; |
1106 | ||
1107 | if (flag_rerun_loop_opt) | |
1108 | { | |
1109 | cleanup_barriers (); | |
1110 | ||
1111 | /* We only want to perform unrolling once. */ | |
c94583fe | 1112 | loop_optimize (get_insns (), dump_file, 0); |
f6db1481 RH |
1113 | |
1114 | /* The first call to loop_optimize makes some instructions | |
1115 | trivially dead. We delete those instructions now in the | |
1116 | hope that doing so will make the heuristics in loop work | |
1117 | better and possibly speed up compilation. */ | |
fd743bc1 | 1118 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
f6db1481 RH |
1119 | |
1120 | /* The regscan pass is currently necessary as the alias | |
1121 | analysis code depends on this information. */ | |
c80a0f26 | 1122 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 RH |
1123 | } |
1124 | cleanup_barriers (); | |
c94583fe | 1125 | loop_optimize (get_insns (), dump_file, do_prefetch); |
f6db1481 RH |
1126 | |
1127 | /* Loop can create trivially dead instructions. */ | |
fd743bc1 | 1128 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
2e09ee33 | 1129 | find_basic_blocks (get_insns ()); |
fd743bc1 | 1130 | close_dump_file (DFI_loop, print_rtl, get_insns ()); |
f6db1481 | 1131 | timevar_pop (TV_LOOP); |
f6db1481 RH |
1132 | |
1133 | ggc_collect (); | |
1134 | } | |
1135 | ||
1136 | /* Perform loop optimizations. It might be better to do them a bit | |
1137 | sooner, but we want the profile feedback to work more | |
1138 | efficiently. */ | |
1139 | static void | |
fd743bc1 | 1140 | rest_of_handle_loop2 (void) |
f6db1481 RH |
1141 | { |
1142 | struct loops *loops; | |
1143 | basic_block bb; | |
1144 | ||
5e962776 ZD |
1145 | if (!flag_move_loop_invariants |
1146 | && !flag_unswitch_loops | |
689ba89d ZD |
1147 | && !flag_peel_loops |
1148 | && !flag_unroll_loops | |
1149 | && !flag_branch_on_count_reg) | |
1150 | return; | |
1151 | ||
f6db1481 | 1152 | timevar_push (TV_LOOP); |
fd743bc1 | 1153 | open_dump_file (DFI_loop2, current_function_decl); |
f6db1481 RH |
1154 | if (dump_file) |
1155 | dump_flow_info (dump_file); | |
1156 | ||
1157 | /* Initialize structures for layout changes. */ | |
35b6b437 | 1158 | cfg_layout_initialize (0); |
f6db1481 RH |
1159 | |
1160 | loops = loop_optimizer_init (dump_file); | |
1161 | ||
1162 | if (loops) | |
1163 | { | |
1164 | /* The optimizations: */ | |
5e962776 ZD |
1165 | if (flag_move_loop_invariants) |
1166 | move_loop_invariants (loops); | |
1167 | ||
f6db1481 RH |
1168 | if (flag_unswitch_loops) |
1169 | unswitch_loops (loops); | |
1170 | ||
1171 | if (flag_peel_loops || flag_unroll_loops) | |
1172 | unroll_and_peel_loops (loops, | |
1173 | (flag_peel_loops ? UAP_PEEL : 0) | | |
1174 | (flag_unroll_loops ? UAP_UNROLL : 0) | | |
1175 | (flag_unroll_all_loops ? UAP_UNROLL_ALL : 0)); | |
1176 | ||
689ba89d ZD |
1177 | #ifdef HAVE_doloop_end |
1178 | if (flag_branch_on_count_reg && HAVE_doloop_end) | |
1179 | doloop_optimize_loops (loops); | |
1180 | #endif /* HAVE_doloop_end */ | |
1181 | ||
f6db1481 RH |
1182 | loop_optimizer_finalize (loops, dump_file); |
1183 | } | |
1184 | ||
8a807136 ZD |
1185 | free_dominance_info (CDI_DOMINATORS); |
1186 | ||
f6db1481 RH |
1187 | /* Finalize layout changes. */ |
1188 | FOR_EACH_BB (bb) | |
1189 | if (bb->next_bb != EXIT_BLOCK_PTR) | |
370369e1 | 1190 | bb->aux = bb->next_bb; |
f6db1481 RH |
1191 | cfg_layout_finalize (); |
1192 | ||
1193 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
fd743bc1 | 1194 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
c80a0f26 | 1195 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 RH |
1196 | if (dump_file) |
1197 | dump_flow_info (dump_file); | |
1198 | close_dump_file (DFI_loop2, print_rtl_with_bb, get_insns ()); | |
1199 | timevar_pop (TV_LOOP); | |
1200 | ggc_collect (); | |
1201 | } | |
1202 | ||
97b0ade3 PB |
1203 | static void |
1204 | rest_of_handle_branch_target_load_optimize (void) | |
f6db1481 | 1205 | { |
97b0ade3 PB |
1206 | static int warned = 0; |
1207 | ||
1208 | /* Leave this a warning for now so that it is possible to experiment | |
1209 | with running this pass twice. In 3.6, we should either make this | |
1210 | an error, or use separate dump files. */ | |
1211 | if (flag_branch_target_load_optimize | |
1212 | && flag_branch_target_load_optimize2 | |
1213 | && !warned) | |
1214 | { | |
d4ee4d25 | 1215 | warning (0, "branch target register load optimization is not intended " |
97b0ade3 | 1216 | "to be run twice"); |
f6db1481 | 1217 | |
97b0ade3 PB |
1218 | warned = 1; |
1219 | } | |
f6db1481 | 1220 | |
97b0ade3 PB |
1221 | open_dump_file (DFI_branch_target_load, current_function_decl); |
1222 | branch_target_load_optimize (epilogue_completed); | |
1223 | close_dump_file (DFI_branch_target_load, print_rtl_with_bb, get_insns ()); | |
f6db1481 | 1224 | ggc_collect (); |
97b0ade3 | 1225 | } |
f6db1481 | 1226 | |
97b0ade3 PB |
1227 | #ifdef OPTIMIZE_MODE_SWITCHING |
1228 | static void | |
1229 | rest_of_handle_mode_switching (void) | |
1230 | { | |
1231 | timevar_push (TV_MODE_SWITCH); | |
f6db1481 | 1232 | |
97b0ade3 PB |
1233 | no_new_pseudos = 0; |
1234 | optimize_mode_switching (NULL); | |
1235 | no_new_pseudos = 1; | |
f6db1481 | 1236 | |
97b0ade3 PB |
1237 | timevar_pop (TV_MODE_SWITCH); |
1238 | } | |
1239 | #endif | |
f6db1481 | 1240 | |
97b0ade3 PB |
1241 | static void |
1242 | rest_of_handle_jump (void) | |
1243 | { | |
1244 | ggc_collect (); | |
f6db1481 RH |
1245 | |
1246 | timevar_push (TV_JUMP); | |
fd743bc1 | 1247 | open_dump_file (DFI_sibling, current_function_decl); |
f6db1481 RH |
1248 | |
1249 | delete_unreachable_blocks (); | |
242229bb | 1250 | #ifdef ENABLE_CHECKING |
97b0ade3 | 1251 | verify_flow_info (); |
242229bb | 1252 | #endif |
9f8628ba PB |
1253 | |
1254 | if (cfun->tail_call_emit) | |
1255 | fixup_tail_calls (); | |
1256 | ||
1257 | close_dump_file (DFI_sibling, print_rtl, get_insns ()); | |
97b0ade3 PB |
1258 | timevar_pop (TV_JUMP); |
1259 | } | |
f6db1481 | 1260 | |
97b0ade3 PB |
1261 | static void |
1262 | rest_of_handle_eh (void) | |
1263 | { | |
f6db1481 RH |
1264 | insn_locators_initialize (); |
1265 | /* Complete generation of exception handling code. */ | |
1266 | if (doing_eh (0)) | |
1267 | { | |
1268 | timevar_push (TV_JUMP); | |
fd743bc1 | 1269 | open_dump_file (DFI_eh, current_function_decl); |
f6db1481 | 1270 | |
3fbd86b1 SB |
1271 | cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL); |
1272 | ||
f6db1481 RH |
1273 | finish_eh_generation (); |
1274 | ||
3fbd86b1 SB |
1275 | cleanup_cfg (CLEANUP_PRE_LOOP | CLEANUP_NO_INSN_DEL); |
1276 | ||
f6db1481 RH |
1277 | close_dump_file (DFI_eh, print_rtl, get_insns ()); |
1278 | timevar_pop (TV_JUMP); | |
1279 | } | |
97b0ade3 | 1280 | } |
f6db1481 | 1281 | |
97b0ade3 PB |
1282 | static void |
1283 | rest_of_handle_stack_adjustments (void) | |
1284 | { | |
1285 | life_analysis (dump_file, PROP_POSTRELOAD); | |
1286 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_UPDATE_LIFE | |
1287 | | (flag_crossjumping ? CLEANUP_CROSSJUMP : 0)); | |
1288 | ||
1289 | /* This is kind of a heuristic. We need to run combine_stack_adjustments | |
1290 | even for machines with possibly nonzero RETURN_POPS_ARGS | |
1291 | and ACCUMULATE_OUTGOING_ARGS. We expect that only ports having | |
1292 | push instructions will have popping returns. */ | |
1293 | #ifndef PUSH_ROUNDING | |
1294 | if (!ACCUMULATE_OUTGOING_ARGS) | |
f6db1481 | 1295 | #endif |
97b0ade3 PB |
1296 | combine_stack_adjustments (); |
1297 | } | |
f6db1481 | 1298 | |
97b0ade3 PB |
1299 | static void |
1300 | rest_of_handle_flow2 (void) | |
1301 | { | |
1302 | timevar_push (TV_FLOW2); | |
1303 | open_dump_file (DFI_flow2, current_function_decl); | |
f6db1481 | 1304 | |
97b0ade3 PB |
1305 | /* Re-create the death notes which were deleted during reload. */ |
1306 | #ifdef ENABLE_CHECKING | |
1307 | verify_flow_info (); | |
1308 | #endif | |
1309 | ||
1310 | /* If optimizing, then go ahead and split insns now. */ | |
1311 | #ifndef STACK_REGS | |
1312 | if (optimize > 0) | |
1313 | #endif | |
1314 | split_all_insns (0); | |
1315 | ||
1316 | if (flag_branch_target_load_optimize) | |
5b5e3a31 R |
1317 | { |
1318 | close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ()); | |
1319 | rest_of_handle_branch_target_load_optimize (); | |
1320 | open_dump_file (DFI_flow2, current_function_decl); | |
1321 | } | |
97b0ade3 | 1322 | |
033797e2 EB |
1323 | if (optimize) |
1324 | cleanup_cfg (CLEANUP_EXPENSIVE); | |
1325 | ||
1326 | /* On some machines, the prologue and epilogue code, or parts thereof, | |
1327 | can be represented as RTL. Doing so lets us schedule insns between | |
1328 | it and the rest of the code and also allows delayed branch | |
1329 | scheduling to operate in the epilogue. */ | |
1330 | thread_prologue_and_epilogue_insns (get_insns ()); | |
1331 | epilogue_completed = 1; | |
97b0ade3 PB |
1332 | |
1333 | if (optimize) | |
1334 | rest_of_handle_stack_adjustments (); | |
1335 | ||
1336 | flow2_completed = 1; | |
1337 | ||
1338 | close_dump_file (DFI_flow2, print_rtl_with_bb, get_insns ()); | |
1339 | timevar_pop (TV_FLOW2); | |
1340 | ||
1341 | ggc_collect (); | |
1342 | } | |
1343 | ||
1344 | ||
1345 | static void | |
1346 | rest_of_handle_jump2 (void) | |
1347 | { | |
fd743bc1 | 1348 | open_dump_file (DFI_jump, current_function_decl); |
f6db1481 RH |
1349 | |
1350 | /* Always do one jump optimization pass to ensure that JUMP_LABEL fields | |
1351 | are initialized and to compute whether control can drop off the end | |
1352 | of the function. */ | |
1353 | ||
1354 | timevar_push (TV_JUMP); | |
1355 | /* Turn NOTE_INSN_EXPECTED_VALUE into REG_BR_PROB. Do this | |
1356 | before jump optimization switches branch directions. */ | |
1357 | if (flag_guess_branch_prob) | |
1358 | expected_value_to_br_prob (); | |
1359 | ||
fd743bc1 | 1360 | delete_trivially_dead_insns (get_insns (), max_reg_num ()); |
c80a0f26 | 1361 | reg_scan (get_insns (), max_reg_num ()); |
f6db1481 RH |
1362 | if (dump_file) |
1363 | dump_flow_info (dump_file); | |
1364 | cleanup_cfg ((optimize ? CLEANUP_EXPENSIVE : 0) | CLEANUP_PRE_LOOP | |
1365 | | (flag_thread_jumps ? CLEANUP_THREADING : 0)); | |
1366 | ||
6de9cd9a DN |
1367 | create_loop_notes (); |
1368 | ||
fd743bc1 | 1369 | purge_line_number_notes (get_insns ()); |
f6db1481 | 1370 | |
f6db1481 RH |
1371 | if (optimize) |
1372 | cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP); | |
1373 | ||
f6db1481 RH |
1374 | /* Jump optimization, and the removal of NULL pointer checks, may |
1375 | have reduced the number of instructions substantially. CSE, and | |
1376 | future passes, allocate arrays whose dimensions involve the | |
1377 | maximum instruction UID, so if we can reduce the maximum UID | |
1378 | we'll save big on memory. */ | |
1379 | renumber_insns (dump_file); | |
f6db1481 | 1380 | |
fd743bc1 | 1381 | close_dump_file (DFI_jump, print_rtl_with_bb, get_insns ()); |
97b0ade3 | 1382 | timevar_pop (TV_JUMP); |
f6db1481 RH |
1383 | |
1384 | ggc_collect (); | |
97b0ade3 PB |
1385 | } |
1386 | ||
1387 | #ifdef HAVE_peephole2 | |
1388 | static void | |
1389 | rest_of_handle_peephole2 (void) | |
1390 | { | |
1391 | timevar_push (TV_PEEPHOLE2); | |
1392 | open_dump_file (DFI_peephole2, current_function_decl); | |
1393 | ||
1394 | peephole2_optimize (dump_file); | |
1395 | ||
1396 | close_dump_file (DFI_peephole2, print_rtl_with_bb, get_insns ()); | |
1397 | timevar_pop (TV_PEEPHOLE2); | |
1398 | } | |
1399 | #endif | |
1400 | ||
1401 | static void | |
1402 | rest_of_handle_postreload (void) | |
1403 | { | |
1404 | timevar_push (TV_RELOAD_CSE_REGS); | |
1405 | open_dump_file (DFI_postreload, current_function_decl); | |
1406 | ||
1407 | /* Do a very simple CSE pass over just the hard registers. */ | |
1408 | reload_cse_regs (get_insns ()); | |
1409 | /* reload_cse_regs can eliminate potentially-trapping MEMs. | |
1410 | Remove any EH edges associated with them. */ | |
1411 | if (flag_non_call_exceptions) | |
25cd19de | 1412 | purge_all_dead_edges (); |
97b0ade3 PB |
1413 | |
1414 | close_dump_file (DFI_postreload, print_rtl_with_bb, get_insns ()); | |
1415 | timevar_pop (TV_RELOAD_CSE_REGS); | |
1416 | } | |
1417 | ||
1418 | static void | |
1419 | rest_of_handle_shorten_branches (void) | |
1420 | { | |
1421 | /* Shorten branches. */ | |
1422 | timevar_push (TV_SHORTEN_BRANCH); | |
1423 | shorten_branches (get_insns ()); | |
1424 | timevar_pop (TV_SHORTEN_BRANCH); | |
1425 | } | |
1426 | ||
1427 | static void | |
1428 | rest_of_clean_state (void) | |
1429 | { | |
0a9aeefd JH |
1430 | rtx insn, next; |
1431 | ||
1432 | /* It is very important to decompose the RTL instruction chain here: | |
1433 | debug information keeps pointing into CODE_LABEL insns inside the function | |
1434 | body. If these remain pointing to the other insns, we end up preserving | |
1435 | whole RTL chain and attached detailed debug info in memory. */ | |
1436 | for (insn = get_insns (); insn; insn = next) | |
1437 | { | |
1438 | next = NEXT_INSN (insn); | |
1439 | NEXT_INSN (insn) = NULL; | |
1440 | PREV_INSN (insn) = NULL; | |
1441 | } | |
97b0ade3 PB |
1442 | |
1443 | /* In case the function was not output, | |
1444 | don't leave any temporary anonymous types | |
1445 | queued up for sdb output. */ | |
1446 | #ifdef SDB_DEBUGGING_INFO | |
1447 | if (write_symbols == SDB_DEBUG) | |
1448 | sdbout_types (NULL_TREE); | |
1449 | #endif | |
1450 | ||
1451 | reload_completed = 0; | |
1452 | epilogue_completed = 0; | |
1453 | flow2_completed = 0; | |
1454 | no_new_pseudos = 0; | |
1455 | ||
1456 | timevar_push (TV_FINAL); | |
1457 | ||
1458 | /* Clear out the insn_length contents now that they are no | |
1459 | longer valid. */ | |
1460 | init_insn_lengths (); | |
1461 | ||
1462 | /* Show no temporary slots allocated. */ | |
1463 | init_temp_slots (); | |
1464 | ||
1465 | free_basic_block_vars (); | |
1466 | free_bb_for_insn (); | |
1467 | ||
1468 | timevar_pop (TV_FINAL); | |
1469 | ||
1470 | if (targetm.binds_local_p (current_function_decl)) | |
1471 | { | |
1472 | int pref = cfun->preferred_stack_boundary; | |
b3f332c6 | 1473 | if (cfun->stack_alignment_needed > cfun->preferred_stack_boundary) |
97b0ade3 PB |
1474 | pref = cfun->stack_alignment_needed; |
1475 | cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary | |
1476 | = pref; | |
1477 | } | |
1478 | ||
1479 | /* Make sure volatile mem refs aren't considered valid operands for | |
1480 | arithmetic insns. We must call this here if this is a nested inline | |
1481 | function, since the above code leaves us in the init_recog state | |
1482 | (from final.c), and the function context push/pop code does not | |
1483 | save/restore volatile_ok. | |
1484 | ||
1485 | ??? Maybe it isn't necessary for expand_start_function to call this | |
1486 | anymore if we do it here? */ | |
1487 | ||
1488 | init_recog_no_volatile (); | |
1489 | ||
1490 | /* We're done with this function. Free up memory if we can. */ | |
1491 | free_after_parsing (cfun); | |
80d8221e | 1492 | free_after_compilation (cfun); |
97b0ade3 PB |
1493 | } |
1494 | \f | |
1495 | ||
3fbd86b1 SB |
1496 | /* This function is called from the pass manager in tree-optimize.c |
1497 | after all tree passes have finished for a single function, and we | |
1498 | have expanded the function body from trees to RTL. | |
1499 | Once we are here, we have decided that we're supposed to output | |
89dbed81 | 1500 | that function, i.e. that we should write assembler code for it. |
3fbd86b1 SB |
1501 | |
1502 | We run a series of low-level passes here on the function's RTL | |
1503 | representation. Each pass is called via a rest_of_* function. */ | |
97b0ade3 | 1504 | |
73dcf3b5 | 1505 | static void |
97b0ade3 PB |
1506 | rest_of_compilation (void) |
1507 | { | |
97b0ade3 PB |
1508 | /* If we're emitting a nested function, make sure its parent gets |
1509 | emitted as well. Doing otherwise confuses debug info. */ | |
1510 | { | |
1511 | tree parent; | |
1512 | for (parent = DECL_CONTEXT (current_function_decl); | |
1513 | parent != NULL_TREE; | |
1514 | parent = get_containing_scope (parent)) | |
1515 | if (TREE_CODE (parent) == FUNCTION_DECL) | |
1516 | TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (parent)) = 1; | |
1517 | } | |
1518 | ||
1519 | /* We are now committed to emitting code for this function. Do any | |
1520 | preparation, such as emitting abstract debug info for the inline | |
1521 | before it gets mangled by optimization. */ | |
1522 | if (cgraph_function_possibly_inlined_p (current_function_decl)) | |
1523 | (*debug_hooks->outlining_inline_function) (current_function_decl); | |
1524 | ||
1525 | /* Remove any notes we don't need. That will make iterating | |
1526 | over the instruction sequence faster, and allow the garbage | |
1527 | collector to reclaim the memory used by the notes. */ | |
1528 | remove_unnecessary_notes (); | |
1529 | ||
1530 | /* Initialize some variables used by the optimizers. */ | |
1531 | init_function_for_compilation (); | |
1532 | ||
1533 | TREE_ASM_WRITTEN (current_function_decl) = 1; | |
1534 | ||
97b0ade3 PB |
1535 | /* Early return if there were errors. We can run afoul of our |
1536 | consistency checks, and there's not really much point in fixing them. */ | |
1537 | if (rtl_dump_and_exit || flag_syntax_only || errorcount || sorrycount) | |
1538 | goto exit_rest_of_compilation; | |
1539 | ||
1540 | rest_of_handle_jump (); | |
97b0ade3 | 1541 | |
97b0ade3 PB |
1542 | rest_of_handle_eh (); |
1543 | ||
1544 | /* Delay emitting hard_reg_initial_value sets until after EH landing pad | |
1545 | generation, which might create new sets. */ | |
1546 | emit_initial_value_sets (); | |
1547 | ||
1548 | #ifdef FINALIZE_PIC | |
1549 | /* If we are doing position-independent code generation, now | |
1550 | is the time to output special prologues and epilogues. | |
1551 | We do not want to do this earlier, because it just clutters | |
1552 | up inline functions with meaningless insns. */ | |
1553 | if (flag_pic) | |
1554 | FINALIZE_PIC; | |
1555 | #endif | |
1556 | ||
1557 | /* Copy any shared structure that should not be shared. */ | |
1558 | unshare_all_rtl (); | |
1559 | ||
97b0ade3 PB |
1560 | /* Instantiate all virtual registers. */ |
1561 | instantiate_virtual_regs (); | |
1562 | ||
1563 | rest_of_handle_jump2 (); | |
f6db1481 RH |
1564 | |
1565 | if (optimize > 0) | |
fd743bc1 | 1566 | rest_of_handle_cse (); |
f6db1481 | 1567 | |
f6db1481 RH |
1568 | if (optimize > 0) |
1569 | { | |
1570 | if (flag_gcse) | |
fd743bc1 | 1571 | rest_of_handle_gcse (); |
f6db1481 RH |
1572 | |
1573 | if (flag_loop_optimize) | |
fd743bc1 | 1574 | rest_of_handle_loop_optimize (); |
f6db1481 RH |
1575 | |
1576 | if (flag_gcse) | |
fd743bc1 | 1577 | rest_of_handle_jump_bypass (); |
f6db1481 RH |
1578 | } |
1579 | ||
1580 | timevar_push (TV_FLOW); | |
fd743bc1 | 1581 | rest_of_handle_cfg (); |
f6db1481 | 1582 | |
5d9f607b JH |
1583 | if (optimize > 0 |
1584 | || ((profile_arc_flag || flag_test_coverage || flag_branch_probabilities) | |
1585 | && !flag_tree_based_profiling)) | |
f6db1481 | 1586 | { |
6de9cd9a DN |
1587 | rtl_register_profile_hooks (); |
1588 | rtl_register_value_prof_hooks (); | |
fd743bc1 | 1589 | rest_of_handle_branch_prob (); |
f6db1481 RH |
1590 | |
1591 | if (flag_branch_probabilities | |
1592 | && flag_profile_values | |
5d9f607b | 1593 | && !flag_tree_based_profiling |
6d9901e7 ZD |
1594 | && (flag_value_profile_transformations |
1595 | || flag_speculative_prefetching)) | |
fd743bc1 | 1596 | rest_of_handle_value_profile_transformations (); |
f6db1481 RH |
1597 | |
1598 | /* Remove the death notes created for vpt. */ | |
1599 | if (flag_profile_values) | |
1600 | count_or_remove_death_notes (NULL, 1); | |
1601 | } | |
1602 | ||
1603 | if (optimize > 0) | |
fd743bc1 | 1604 | rest_of_handle_if_conversion (); |
f6db1481 | 1605 | |
97b0ade3 | 1606 | if (optimize > 0 && flag_tracer) |
fd743bc1 | 1607 | rest_of_handle_tracer (); |
f6db1481 | 1608 | |
5e962776 ZD |
1609 | if (optimize > 0 |
1610 | && flag_loop_optimize2) | |
fd743bc1 | 1611 | rest_of_handle_loop2 (); |
f6db1481 | 1612 | |
97b0ade3 | 1613 | if (optimize > 0 && flag_web) |
fd743bc1 | 1614 | rest_of_handle_web (); |
f6db1481 | 1615 | |
97b0ade3 | 1616 | if (optimize > 0 && flag_rerun_cse_after_loop) |
fd743bc1 | 1617 | rest_of_handle_cse2 (); |
f6db1481 RH |
1618 | |
1619 | cse_not_expected = 1; | |
1620 | ||
fd743bc1 | 1621 | rest_of_handle_life (); |
97b0ade3 | 1622 | timevar_pop (TV_FLOW); |
f6db1481 RH |
1623 | |
1624 | if (optimize > 0) | |
fd743bc1 | 1625 | rest_of_handle_combine (); |
f6db1481 | 1626 | |
97b0ade3 | 1627 | if (optimize > 0 && flag_if_conversion) |
fd743bc1 | 1628 | rest_of_handle_if_after_combine (); |
f6db1481 | 1629 | |
750054a2 | 1630 | /* The optimization to partition hot/cold basic blocks into separate |
8e8d5162 CT |
1631 | sections of the .o file does not work well with linkonce or with |
1632 | user defined section attributes. Don't call it if either case | |
1633 | arises. */ | |
750054a2 | 1634 | |
9fb32434 CT |
1635 | if (flag_reorder_blocks_and_partition |
1636 | && !DECL_ONE_ONLY (current_function_decl) | |
1637 | && !user_defined_section_attribute) | |
97b0ade3 | 1638 | rest_of_handle_partition_blocks (); |
750054a2 | 1639 | |
1ab219d3 | 1640 | if (optimize > 0 && flag_regmove) |
fd743bc1 | 1641 | rest_of_handle_regmove (); |
f6db1481 RH |
1642 | |
1643 | /* Do unconditional splitting before register allocation to allow machine | |
1644 | description to add extra information not needed previously. */ | |
1645 | split_all_insns (1); | |
1646 | ||
1647 | #ifdef OPTIMIZE_MODE_SWITCHING | |
97b0ade3 | 1648 | rest_of_handle_mode_switching (); |
f6db1481 RH |
1649 | #endif |
1650 | ||
1651 | /* Any of the several passes since flow1 will have munged register | |
1652 | lifetime data a bit. We need it to be up to date for scheduling | |
1653 | (see handling of reg_known_equiv in init_alias_analysis). */ | |
e22857eb | 1654 | recompute_reg_usage (); |
f6db1481 RH |
1655 | |
1656 | #ifdef INSN_SCHEDULING | |
97b0ade3 PB |
1657 | if (optimize > 0 && flag_modulo_sched) |
1658 | rest_of_handle_sms (); | |
1659 | ||
1660 | if (flag_schedule_insns) | |
1661 | rest_of_handle_sched (); | |
f6db1481 RH |
1662 | #endif |
1663 | ||
1664 | /* Determine if the current function is a leaf before running reload | |
1665 | since this can impact optimizations done by the prologue and | |
1666 | epilogue thus changing register elimination offsets. */ | |
1667 | current_function_is_leaf = leaf_function_p (); | |
1668 | ||
cd280abb PB |
1669 | if (rest_of_handle_old_regalloc ()) |
1670 | goto exit_rest_of_compilation; | |
f6db1481 | 1671 | |
f6db1481 | 1672 | if (optimize > 0) |
97b0ade3 | 1673 | rest_of_handle_postreload (); |
f6db1481 | 1674 | |
f9957958 | 1675 | if (optimize > 0 && flag_gcse_after_reload) |
fd743bc1 | 1676 | rest_of_handle_gcse2 (); |
f9957958 | 1677 | |
97b0ade3 | 1678 | rest_of_handle_flow2 (); |
f6db1481 RH |
1679 | |
1680 | #ifdef HAVE_peephole2 | |
1681 | if (optimize > 0 && flag_peephole2) | |
97b0ade3 | 1682 | rest_of_handle_peephole2 (); |
f6db1481 RH |
1683 | #endif |
1684 | ||
97b0ade3 PB |
1685 | if (optimize > 0) |
1686 | rest_of_handle_if_after_reload (); | |
f6db1481 RH |
1687 | |
1688 | if (optimize > 0) | |
1689 | { | |
1690 | if (flag_rename_registers || flag_cprop_registers) | |
fd743bc1 | 1691 | rest_of_handle_regrename (); |
f6db1481 | 1692 | |
fd743bc1 | 1693 | rest_of_handle_reorder_blocks (); |
f6db1481 RH |
1694 | } |
1695 | ||
1696 | if (flag_branch_target_load_optimize2) | |
97b0ade3 | 1697 | rest_of_handle_branch_target_load_optimize (); |
f6db1481 | 1698 | |
f6db1481 RH |
1699 | #ifdef LEAF_REGISTERS |
1700 | current_function_uses_only_leaf_regs | |
1701 | = optimize > 0 && only_leaf_regs_used () && leaf_function_p (); | |
1702 | #endif | |
1703 | ||
9ac617d4 EB |
1704 | #ifdef INSN_SCHEDULING |
1705 | if (optimize > 0 && flag_schedule_insns_after_reload) | |
1706 | rest_of_handle_sched2 (); | |
1707 | #endif | |
1708 | ||
f6db1481 | 1709 | #ifdef STACK_REGS |
fd743bc1 | 1710 | rest_of_handle_stack_regs (); |
f6db1481 RH |
1711 | #endif |
1712 | ||
1713 | compute_alignments (); | |
1714 | ||
bbcb0c05 SB |
1715 | /* Aggressively duplicate basic blocks ending in computed gotos to the |
1716 | tails of their predecessors, unless we are optimizing for size. */ | |
1717 | if (flag_expensive_optimizations && !optimize_size) | |
1718 | duplicate_computed_gotos (); | |
1719 | ||
f6db1481 | 1720 | if (flag_var_tracking) |
fd743bc1 | 1721 | rest_of_handle_variable_tracking (); |
f6db1481 RH |
1722 | |
1723 | /* CFG is no longer maintained up-to-date. */ | |
1724 | free_bb_for_insn (); | |
1725 | ||
1726 | if (targetm.machine_dependent_reorg != 0) | |
fd743bc1 | 1727 | rest_of_handle_machine_reorg (); |
f6db1481 | 1728 | |
fd743bc1 | 1729 | purge_line_number_notes (get_insns ()); |
f6db1481 RH |
1730 | cleanup_barriers (); |
1731 | ||
1732 | #ifdef DELAY_SLOTS | |
97b0ade3 | 1733 | if (flag_delayed_branch) |
fd743bc1 | 1734 | rest_of_handle_delay_slots (); |
f6db1481 RH |
1735 | #endif |
1736 | ||
1737 | #if defined (HAVE_ATTR_length) && !defined (STACK_REGS) | |
1738 | timevar_push (TV_SHORTEN_BRANCH); | |
1739 | split_all_insns_noflow (); | |
1740 | timevar_pop (TV_SHORTEN_BRANCH); | |
1741 | #endif | |
1742 | ||
1743 | convert_to_eh_region_ranges (); | |
1744 | ||
97b0ade3 | 1745 | rest_of_handle_shorten_branches (); |
f6db1481 RH |
1746 | |
1747 | set_nothrow_function_flags (); | |
f6db1481 | 1748 | |
fd743bc1 | 1749 | rest_of_handle_final (); |
f6db1481 | 1750 | |
f6db1481 RH |
1751 | exit_rest_of_compilation: |
1752 | ||
97b0ade3 | 1753 | rest_of_clean_state (); |
f6db1481 RH |
1754 | } |
1755 | ||
f6db1481 RH |
1756 | void |
1757 | finish_optimization_passes (void) | |
1758 | { | |
9f8628ba PB |
1759 | enum tree_dump_index i; |
1760 | struct dump_file_info *dfi; | |
1761 | char *name; | |
1762 | ||
97b0ade3 | 1763 | timevar_push (TV_DUMP); |
f6db1481 RH |
1764 | if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities) |
1765 | { | |
f6db1481 | 1766 | open_dump_file (DFI_bp, NULL); |
f6db1481 | 1767 | end_branch_prob (); |
f6db1481 | 1768 | close_dump_file (DFI_bp, NULL, NULL_RTX); |
f6db1481 RH |
1769 | } |
1770 | ||
1771 | if (optimize > 0 && open_dump_file (DFI_combine, NULL)) | |
1772 | { | |
f6db1481 RH |
1773 | dump_combine_total_stats (dump_file); |
1774 | close_dump_file (DFI_combine, NULL, NULL_RTX); | |
f6db1481 RH |
1775 | } |
1776 | ||
f6db1481 RH |
1777 | /* Do whatever is necessary to finish printing the graphs. */ |
1778 | if (graph_dump_format != no_graph) | |
9f8628ba PB |
1779 | for (i = DFI_MIN; (dfi = get_dump_file_info (i)) != NULL; ++i) |
1780 | if (dump_initialized_p (i) | |
1781 | && (dfi->flags & TDF_RTL) != 0 | |
1782 | && (name = get_dump_file_name (i)) != NULL) | |
1783 | { | |
1784 | finish_graph_dump_file (name); | |
1785 | free (name); | |
1786 | } | |
f6db1481 | 1787 | |
97b0ade3 | 1788 | timevar_pop (TV_DUMP); |
f6db1481 RH |
1789 | } |
1790 | ||
2f8e398b PB |
1791 | struct tree_opt_pass pass_rest_of_compilation = |
1792 | { | |
9f8628ba | 1793 | NULL, /* name */ |
2f8e398b PB |
1794 | NULL, /* gate */ |
1795 | rest_of_compilation, /* execute */ | |
1796 | NULL, /* sub */ | |
1797 | NULL, /* next */ | |
1798 | 0, /* static_pass_number */ | |
1799 | TV_REST_OF_COMPILATION, /* tv_id */ | |
1800 | PROP_rtl, /* properties_required */ | |
1801 | 0, /* properties_provided */ | |
1802 | PROP_rtl, /* properties_destroyed */ | |
1803 | 0, /* todo_flags_start */ | |
9f8628ba PB |
1804 | TODO_ggc_collect, /* todo_flags_finish */ |
1805 | 0 /* letter */ | |
2f8e398b PB |
1806 | }; |
1807 | ||
1808 |