X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Ftree-cfg.c;h=0869edcadaaf006a9a1de8858849231305980782;hp=9f0d1e5bac4126bb649fff7be5ae31b9ffa0bb49;hb=fcd2418b07cdd4737eeea874b53e4b2cb92275b1;hpb=4f217f6965e82cb382ac08e5949f87cf9b154da3 diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 9f0d1e5bac4..0869edcadaa 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -45,6 +45,7 @@ Boston, MA 02111-1307, USA. */ #include "cfgloop.h" #include "cfglayout.h" #include "hashtab.h" +#include "tree-ssa-propagate.h" /* This file contains functions for building the Control Flow Graph (CFG) for a function tree. */ @@ -212,6 +213,10 @@ build_tree_cfg (tree *tp) } } +#ifdef ENABLE_CHECKING + verify_stmts (); +#endif + /* Dump a textual representation of the flowgraph. */ if (dump_file) dump_tree_cfg (dump_file, dump_flags); @@ -442,7 +447,7 @@ create_bb (void *h, void *e, basic_block after) /* Fold COND_EXPR_COND of each COND_EXPR. */ -static void +void fold_cond_expr_cond (void) { basic_block bb; @@ -1257,6 +1262,7 @@ tree_can_merge_blocks_p (basic_block a, basic_block b) { tree stmt; block_stmt_iterator bsi; + tree phi; if (!single_succ_p (a)) return false; @@ -1284,9 +1290,19 @@ tree_can_merge_blocks_p (basic_block a, basic_block b) && DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt))) return false; - /* There may be no PHI nodes at the start of B. */ - if (phi_nodes (b)) - return false; + /* It must be possible to eliminate all phi nodes in B. If ssa form + is not up-to-date, we cannot eliminate any phis. */ + phi = phi_nodes (b); + if (phi) + { + if (need_ssa_update_p ()) + return false; + + for (; phi; phi = PHI_CHAIN (phi)) + if (!is_gimple_reg (PHI_RESULT (phi)) + && !may_propagate_copy (PHI_RESULT (phi), PHI_ARG_DEF (phi, 0))) + return false; + } /* Do not remove user labels. */ for (bsi = bsi_start (b); !bsi_end_p (bsi); bsi_next (&bsi)) @@ -1306,6 +1322,62 @@ tree_can_merge_blocks_p (basic_block a, basic_block b) return true; } +/* Replaces all uses of NAME by VAL. */ + +void +replace_uses_by (tree name, tree val) +{ + imm_use_iterator imm_iter; + use_operand_p use; + tree stmt; + edge e; + unsigned i; + VEC(tree,heap) *stmts = VEC_alloc (tree, heap, 20); + + FOR_EACH_IMM_USE_SAFE (use, imm_iter, name) + { + stmt = USE_STMT (use); + + SET_USE (use, val); + + if (TREE_CODE (stmt) == PHI_NODE) + { + e = PHI_ARG_EDGE (stmt, PHI_ARG_INDEX_FROM_USE (use)); + if (e->flags & EDGE_ABNORMAL) + { + /* This can only occur for virtual operands, since + for the real ones SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name)) + would prevent replacement. */ + gcc_assert (!is_gimple_reg (name)); + SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val) = 1; + } + } + else + VEC_safe_push (tree, heap, stmts, stmt); + } + + /* We do not update the statements in the loop above. Consider + x = w * w; + + If we performed the update in the first loop, the statement + would be rescanned after first occurrence of w is replaced, + the new uses would be placed to the beginning of the list, + and we would never process them. */ + for (i = 0; VEC_iterate (tree, stmts, i, stmt); i++) + { + tree rhs; + + fold_stmt_inplace (stmt); + + rhs = get_rhs (stmt); + if (TREE_CODE (rhs) == ADDR_EXPR) + recompute_tree_invarant_for_addr_expr (rhs); + + update_stmt (stmt); + } + + VEC_free (tree, heap, stmts); +} /* Merge block B into block A. */ @@ -1314,10 +1386,40 @@ tree_merge_blocks (basic_block a, basic_block b) { block_stmt_iterator bsi; tree_stmt_iterator last; + tree phi; if (dump_file) fprintf (dump_file, "Merging blocks %d and %d\n", a->index, b->index); + /* Remove the phi nodes. */ + bsi = bsi_last (a); + for (phi = phi_nodes (b); phi; phi = phi_nodes (b)) + { + tree def = PHI_RESULT (phi), use = PHI_ARG_DEF (phi, 0); + tree copy; + + if (!may_propagate_copy (def, use) + /* Propagating pointers might cause the set of vops for statements + to be changed, and thus require ssa form update. */ + || (is_gimple_reg (def) + && POINTER_TYPE_P (TREE_TYPE (def)))) + { + gcc_assert (is_gimple_reg (def)); + + /* Note that just emitting the copies is fine -- there is no problem + with ordering of phi nodes. This is because A is the single + predecessor of B, therefore results of the phi nodes cannot + appear as arguments of the phi nodes. */ + copy = build2 (MODIFY_EXPR, void_type_node, def, use); + bsi_insert_after (&bsi, copy, BSI_NEW_STMT); + SET_PHI_RESULT (phi, NULL_TREE); + SSA_NAME_DEF_STMT (def) = copy; + } + else + replace_uses_by (def, use); + remove_phi_node (phi, NULL); + } + /* Ensure that B follows A. */ move_block_after (b, a); @@ -5626,14 +5728,6 @@ execute_warn_function_return (void) edge e; edge_iterator ei; - if (warn_missing_noreturn - && !TREE_THIS_VOLATILE (cfun->decl) - && EDGE_COUNT (EXIT_BLOCK_PTR->preds) == 0 - && !lang_hooks.function.missing_noreturn_ok_p (cfun->decl)) - warning (0, "%Jfunction might be possible candidate for " - "attribute %", - cfun->decl); - /* If we have a path to EXIT, then we do return. */ if (TREE_THIS_VOLATILE (cfun->decl) && EDGE_COUNT (EXIT_BLOCK_PTR->preds) > 0) @@ -5737,3 +5831,34 @@ struct tree_opt_pass pass_warn_function_return = 0, /* todo_flags_finish */ 0 /* letter */ }; + +/* Emit noreturn warnings. */ + +static void +execute_warn_function_noreturn (void) +{ + if (warn_missing_noreturn + && !TREE_THIS_VOLATILE (cfun->decl) + && EDGE_COUNT (EXIT_BLOCK_PTR->preds) == 0 + && !lang_hooks.function.missing_noreturn_ok_p (cfun->decl)) + warning (0, "%Jfunction might be possible candidate for " + "attribute %", + cfun->decl); +} + +struct tree_opt_pass pass_warn_function_noreturn = +{ + NULL, /* name */ + NULL, /* gate */ + execute_warn_function_noreturn, /* execute */ + NULL, /* sub */ + NULL, /* next */ + 0, /* static_pass_number */ + 0, /* tv_id */ + PROP_cfg, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ + 0 /* letter */ +};