diff options
Diffstat (limited to 'gcc/tree-ssa-loop-manip.c')
-rw-r--r-- | gcc/tree-ssa-loop-manip.c | 51 |
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 |