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