comparison gcc/tree-cfgcleanup.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
1 /* CFG cleanup for trees. 1 /* CFG cleanup for trees.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify 7 GCC is free software; you can redistribute it and/or modify
21 #include "config.h" 21 #include "config.h"
22 #include "system.h" 22 #include "system.h"
23 #include "coretypes.h" 23 #include "coretypes.h"
24 #include "tm.h" 24 #include "tm.h"
25 #include "tree.h" 25 #include "tree.h"
26 #include "rtl.h"
27 #include "tm_p.h" 26 #include "tm_p.h"
28 #include "hard-reg-set.h"
29 #include "basic-block.h" 27 #include "basic-block.h"
30 #include "output.h" 28 #include "output.h"
31 #include "toplev.h" 29 #include "toplev.h"
32 #include "flags.h" 30 #include "flags.h"
33 #include "function.h" 31 #include "function.h"
88 if (!single_succ_p (bb)) 86 if (!single_succ_p (bb))
89 { 87 {
90 edge e; 88 edge e;
91 edge_iterator ei; 89 edge_iterator ei;
92 bool warned; 90 bool warned;
91 location_t loc;
93 92
94 fold_defer_overflow_warnings (); 93 fold_defer_overflow_warnings ();
95 val = gimple_fold (stmt); 94 loc = gimple_location (stmt);
95 switch (gimple_code (stmt))
96 {
97 case GIMPLE_COND:
98 {
99 tree lhs = gimple_cond_lhs (stmt);
100 tree rhs = gimple_cond_rhs (stmt);
101 /* For conditions try harder and lookup single-argument
102 PHI nodes. Only do so from the same basic-block though
103 as other basic-blocks may be dead already. */
104 if (TREE_CODE (lhs) == SSA_NAME
105 && !name_registered_for_update_p (lhs))
106 {
107 gimple def_stmt = SSA_NAME_DEF_STMT (lhs);
108 if (gimple_code (def_stmt) == GIMPLE_PHI
109 && gimple_phi_num_args (def_stmt) == 1
110 && gimple_bb (def_stmt) == gimple_bb (stmt)
111 && (TREE_CODE (PHI_ARG_DEF (def_stmt, 0)) != SSA_NAME
112 || !name_registered_for_update_p (PHI_ARG_DEF (def_stmt,
113 0))))
114 lhs = PHI_ARG_DEF (def_stmt, 0);
115 }
116 if (TREE_CODE (rhs) == SSA_NAME
117 && !name_registered_for_update_p (rhs))
118 {
119 gimple def_stmt = SSA_NAME_DEF_STMT (rhs);
120 if (gimple_code (def_stmt) == GIMPLE_PHI
121 && gimple_phi_num_args (def_stmt) == 1
122 && gimple_bb (def_stmt) == gimple_bb (stmt)
123 && (TREE_CODE (PHI_ARG_DEF (def_stmt, 0)) != SSA_NAME
124 || !name_registered_for_update_p (PHI_ARG_DEF (def_stmt,
125 0))))
126 rhs = PHI_ARG_DEF (def_stmt, 0);
127 }
128 val = fold_binary_loc (loc, gimple_cond_code (stmt),
129 boolean_type_node, lhs, rhs);
130 break;
131 }
132
133 case GIMPLE_SWITCH:
134 val = gimple_switch_index (stmt);
135 break;
136
137 default:
138 val = NULL_TREE;
139 }
96 taken_edge = find_taken_edge (bb, val); 140 taken_edge = find_taken_edge (bb, val);
97 if (!taken_edge) 141 if (!taken_edge)
98 { 142 {
99 fold_undefer_and_ignore_overflow_warnings (); 143 fold_undefer_and_ignore_overflow_warnings ();
100 return false; 144 return false;
219 263
220 static bool 264 static bool
221 tree_forwarder_block_p (basic_block bb, bool phi_wanted) 265 tree_forwarder_block_p (basic_block bb, bool phi_wanted)
222 { 266 {
223 gimple_stmt_iterator gsi; 267 gimple_stmt_iterator gsi;
268 location_t locus;
224 269
225 /* BB must have a single outgoing edge. */ 270 /* BB must have a single outgoing edge. */
226 if (single_succ_p (bb) != 1 271 if (single_succ_p (bb) != 1
227 /* If PHI_WANTED is false, BB must not have any PHI nodes. 272 /* If PHI_WANTED is false, BB must not have any PHI nodes.
228 Otherwise, BB must have PHI nodes. */ 273 Otherwise, BB must have PHI nodes. */
237 282
238 #if ENABLE_CHECKING 283 #if ENABLE_CHECKING
239 gcc_assert (bb != ENTRY_BLOCK_PTR); 284 gcc_assert (bb != ENTRY_BLOCK_PTR);
240 #endif 285 #endif
241 286
287 locus = single_succ_edge (bb)->goto_locus;
288
242 /* There should not be an edge coming from entry, or an EH edge. */ 289 /* There should not be an edge coming from entry, or an EH edge. */
243 { 290 {
244 edge_iterator ei; 291 edge_iterator ei;
245 edge e; 292 edge e;
246 293
247 FOR_EACH_EDGE (e, ei, bb->preds) 294 FOR_EACH_EDGE (e, ei, bb->preds)
248 if (e->src == ENTRY_BLOCK_PTR || (e->flags & EDGE_EH)) 295 if (e->src == ENTRY_BLOCK_PTR || (e->flags & EDGE_EH))
249 return false; 296 return false;
297 /* If goto_locus of any of the edges differs, prevent removing
298 the forwarder block for -O0. */
299 else if (optimize == 0 && e->goto_locus != locus)
300 return false;
250 } 301 }
251 302
252 /* Now walk through the statements backward. We can ignore labels, 303 /* Now walk through the statements backward. We can ignore labels,
253 anything else means this is not a forwarder block. */ 304 anything else means this is not a forwarder block. */
254 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) 305 for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi))
257 308
258 switch (gimple_code (stmt)) 309 switch (gimple_code (stmt))
259 { 310 {
260 case GIMPLE_LABEL: 311 case GIMPLE_LABEL:
261 if (DECL_NONLOCAL (gimple_label_label (stmt))) 312 if (DECL_NONLOCAL (gimple_label_label (stmt)))
313 return false;
314 if (optimize == 0 && gimple_location (stmt) != locus)
262 return false; 315 return false;
263 break; 316 break;
264 317
265 /* ??? For now, hope there's a corresponding debug 318 /* ??? For now, hope there's a corresponding debug
266 assignment at the destination. */ 319 assignment at the destination. */
336 edge succ = single_succ_edge (bb), e, s; 389 edge succ = single_succ_edge (bb), e, s;
337 basic_block dest = succ->dest; 390 basic_block dest = succ->dest;
338 gimple label; 391 gimple label;
339 edge_iterator ei; 392 edge_iterator ei;
340 gimple_stmt_iterator gsi, gsi_to; 393 gimple_stmt_iterator gsi, gsi_to;
341 bool seen_abnormal_edge = false; 394 bool can_move_debug_stmts;
342 395
343 /* We check for infinite loops already in tree_forwarder_block_p. 396 /* We check for infinite loops already in tree_forwarder_block_p.
344 However it may happen that the infinite loop is created 397 However it may happen that the infinite loop is created
345 afterwards due to removal of forwarders. */ 398 afterwards due to removal of forwarders. */
346 if (dest == bb) 399 if (dest == bb)
347 return false; 400 return false;
348 401
349 /* If the destination block consists of a nonlocal label, do not merge 402 /* If the destination block consists of a nonlocal label or is a
350 it. */ 403 EH landing pad, do not merge it. */
351 label = first_stmt (dest); 404 label = first_stmt (dest);
352 if (label 405 if (label
353 && gimple_code (label) == GIMPLE_LABEL 406 && gimple_code (label) == GIMPLE_LABEL
354 && DECL_NONLOCAL (gimple_label_label (label))) 407 && (DECL_NONLOCAL (gimple_label_label (label))
408 || EH_LANDING_PAD_NR (gimple_label_label (label)) != 0))
355 return false; 409 return false;
356 410
357 /* If there is an abnormal edge to basic block BB, but not into 411 /* If there is an abnormal edge to basic block BB, but not into
358 dest, problems might occur during removal of the phi node at out 412 dest, problems might occur during removal of the phi node at out
359 of ssa due to overlapping live ranges of registers. 413 of ssa due to overlapping live ranges of registers.
363 two different eh regions, and rest of exception handling code 417 two different eh regions, and rest of exception handling code
364 does not like it. 418 does not like it.
365 419
366 So if there is an abnormal edge to BB, proceed only if there is 420 So if there is an abnormal edge to BB, proceed only if there is
367 no abnormal edge to DEST and there are no phi nodes in DEST. */ 421 no abnormal edge to DEST and there are no phi nodes in DEST. */
368 if (has_abnormal_incoming_edge_p (bb)) 422 if (has_abnormal_incoming_edge_p (bb)
369 { 423 && (has_abnormal_incoming_edge_p (dest)
370 seen_abnormal_edge = true; 424 || !gimple_seq_empty_p (phi_nodes (dest))))
371 425 return false;
372 if (has_abnormal_incoming_edge_p (dest)
373 || !gimple_seq_empty_p (phi_nodes (dest)))
374 return false;
375 }
376 426
377 /* If there are phi nodes in DEST, and some of the blocks that are 427 /* If there are phi nodes in DEST, and some of the blocks that are
378 predecessors of BB are also predecessors of DEST, check that the 428 predecessors of BB are also predecessors of DEST, check that the
379 phi node arguments match. */ 429 phi node arguments match. */
380 if (!gimple_seq_empty_p (phi_nodes (dest))) 430 if (!gimple_seq_empty_p (phi_nodes (dest)))
387 437
388 if (!phi_alternatives_equal (dest, succ, s)) 438 if (!phi_alternatives_equal (dest, succ, s))
389 return false; 439 return false;
390 } 440 }
391 } 441 }
442
443 can_move_debug_stmts = single_pred_p (dest);
392 444
393 /* Redirect the edges. */ 445 /* Redirect the edges. */
394 for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); ) 446 for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); )
395 { 447 {
396 bitmap_set_bit (cfgcleanup_altered_bbs, e->src->index); 448 bitmap_set_bit (cfgcleanup_altered_bbs, e->src->index);
417 add_phi_arg (phi, gimple_phi_arg_def (phi, succ->dest_idx), s, l); 469 add_phi_arg (phi, gimple_phi_arg_def (phi, succ->dest_idx), s, l);
418 } 470 }
419 } 471 }
420 } 472 }
421 473
422 if (seen_abnormal_edge) 474 /* Move nonlocal labels and computed goto targets as well as user
423 { 475 defined labels and labels with an EH landing pad number to the
424 /* Move the labels to the new block, so that the redirection of 476 new block, so that the redirection of the abnormal edges works,
425 the abnormal edges works. */ 477 jump targets end up in a sane place and debug information for
426 gsi_to = gsi_start_bb (dest); 478 labels is retained. */
427 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); ) 479 gsi_to = gsi_start_bb (dest);
428 { 480 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); )
429 label = gsi_stmt (gsi); 481 {
430 gcc_assert (gimple_code (label) == GIMPLE_LABEL 482 tree decl;
431 || is_gimple_debug (label)); 483 label = gsi_stmt (gsi);
484 if (is_gimple_debug (label))
485 break;
486 decl = gimple_label_label (label);
487 if (EH_LANDING_PAD_NR (decl) != 0
488 || DECL_NONLOCAL (decl)
489 || FORCED_LABEL (decl)
490 || !DECL_ARTIFICIAL (decl))
491 {
432 gsi_remove (&gsi, false); 492 gsi_remove (&gsi, false);
433 gsi_insert_before (&gsi_to, label, GSI_SAME_STMT); 493 gsi_insert_before (&gsi_to, label, GSI_SAME_STMT);
494 }
495 else
496 gsi_next (&gsi);
497 }
498
499 /* Move debug statements if the destination has just a single
500 predecessor. */
501 if (can_move_debug_stmts)
502 {
503 gsi_to = gsi_after_labels (dest);
504 for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); )
505 {
506 gimple debug = gsi_stmt (gsi);
507 if (!is_gimple_debug (debug))
508 break;
509 gsi_remove (&gsi, false);
510 gsi_insert_before (&gsi_to, debug, GSI_SAME_STMT);
434 } 511 }
435 } 512 }
436 513
437 bitmap_set_bit (cfgcleanup_altered_bbs, dest->index); 514 bitmap_set_bit (cfgcleanup_altered_bbs, dest->index);
438 515
536 if (cleanup_omp_return (bb)) 613 if (cleanup_omp_return (bb))
537 return true; 614 return true;
538 615
539 retval = cleanup_control_flow_bb (bb); 616 retval = cleanup_control_flow_bb (bb);
540 617
541 /* Forwarder blocks can carry line number information which is 618 if (tree_forwarder_block_p (bb, false)
542 useful when debugging, so we only clean them up when
543 optimizing. */
544 if (optimize > 0
545 && tree_forwarder_block_p (bb, false)
546 && remove_forwarder_block (bb)) 619 && remove_forwarder_block (bb))
547 return true; 620 return true;
548 621
549 /* Merging the blocks may create new opportunities for folding 622 /* Merging the blocks may create new opportunities for folding
550 conditional branches (due to the elimination of single-valued PHI 623 conditional branches (due to the elimination of single-valued PHI
854 927
855 dest = single_succ (bb); 928 dest = single_succ (bb);
856 929
857 /* We have to feed into another basic block with PHI 930 /* We have to feed into another basic block with PHI
858 nodes. */ 931 nodes. */
859 if (!phi_nodes (dest) 932 if (gimple_seq_empty_p (phi_nodes (dest))
860 /* We don't want to deal with a basic block with 933 /* We don't want to deal with a basic block with
861 abnormal edges. */ 934 abnormal edges. */
862 || has_abnormal_incoming_edge_p (bb)) 935 || has_abnormal_incoming_edge_p (bb))
863 continue; 936 continue;
864 937