aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-manip.c
diff options
context:
space:
mode:
authorTom de Vries <tom@codesourcery.com>2015-07-07 16:25:12 +0000
committerTom de Vries <vries@gcc.gnu.org>2015-07-07 16:25:12 +0000
commit338392ed0fd9ca466905860e931b7a480179bce4 (patch)
tree3eb1e7150ba1a00608cd3f4c2b16ae22ac5438b1 /gcc/tree-ssa-loop-manip.c
parent9b20858a9ba7039a12cef6e724e541bdcce2ba25 (diff)
downloadgcc-338392ed0fd9ca466905860e931b7a480179bce4.zip
gcc-338392ed0fd9ca466905860e931b7a480179bce4.tar.gz
gcc-338392ed0fd9ca466905860e931b7a480179bce4.tar.bz2
Add rewrite_virtuals_into_loop_closed_ssa
2015-07-07 Tom de Vries <tom@codesourcery.com> * tree-cfg.c (get_virtual_phi): New function. * tree-cfg.h (get_virtual_phi): Declare. * tree-ssa-loop-manip.c (replace_uses_in_dominated_bbs) (rewrite_virtuals_into_loop_closed_ssa): New function. * tree-ssa-loop-manip.h (rewrite_virtuals_into_loop_closed_ssa): Declare. * tree-parloops.c (replace_uses_in_bbs_by): Remove. (transform_to_exit_first_loop_alt): Use rewrite_virtuals_into_loop_closed_ssa. From-SVN: r225520
Diffstat (limited to 'gcc/tree-ssa-loop-manip.c')
-rw-r--r--gcc/tree-ssa-loop-manip.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
index a72b779..3fbb456 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -560,6 +560,57 @@ rewrite_into_loop_closed_ssa (bitmap changed_bbs, unsigned update_flag)
free (use_blocks);
}
+/* Replace uses of OLD_VAL with NEW_VAL in bbs dominated by BB. */
+
+static void
+replace_uses_in_dominated_bbs (tree old_val, tree new_val, basic_block bb)
+{
+ gimple use_stmt;
+ imm_use_iterator imm_iter;
+
+ FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, old_val)
+ {
+ if (!dominated_by_p (CDI_DOMINATORS, gimple_bb (use_stmt), bb))
+ continue;
+
+ use_operand_p use_p;
+ FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+ SET_USE (use_p, new_val);
+ }
+}
+
+/* Ensure a virtual phi is present in the exit block, if LOOP contains a vdef.
+ In other words, ensure loop-closed ssa normal form for virtuals. Handles
+ only loops with a single exit that dominates the latch. */
+
+void
+rewrite_virtuals_into_loop_closed_ssa (struct loop *loop)
+{
+ gphi *phi;
+ /* TODO: Handle !single_dom_exit loops. */
+ edge exit = single_dom_exit (loop);
+ gcc_assert (exit != NULL);
+
+ phi = get_virtual_phi (loop->header);
+ if (phi == NULL)
+ return;
+
+ tree final_loop = PHI_ARG_DEF_FROM_EDGE (phi, single_succ_edge (loop->latch));
+
+ phi = get_virtual_phi (exit->dest);
+ if (phi != NULL)
+ {
+ tree final_exit = PHI_ARG_DEF_FROM_EDGE (phi, exit);
+ gcc_assert (operand_equal_p (final_loop, final_exit, 0));
+ return;
+ }
+
+ tree res_new = copy_ssa_name (final_loop, NULL);
+ gphi *nphi = create_phi_node (res_new, exit->dest);
+ replace_uses_in_dominated_bbs (final_loop, res_new, exit->dest);
+ add_phi_arg (nphi, final_loop, exit, UNKNOWN_LOCATION);
+}
+
/* Check invariants of the loop closed ssa form for the USE in BB. */
static void