+ find_uses_to_rename_bb (bb, use_blocks, need_phis, use_flags);
+}
+
+/* Mark uses of DEF that are used outside of the loop they are defined in for
+ rewrite. Record the set of blocks in which the ssa names are used to
+ USE_BLOCKS. Record the SSA names that will need exit PHIs in NEED_PHIS. */
+
+static void
+find_uses_to_rename_def (tree def, bitmap *use_blocks, bitmap need_phis)
+{
+ gimple use_stmt;
+ imm_use_iterator imm_iter;
+
+ FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
+ {
+ basic_block use_bb = gimple_bb (use_stmt);
+
+ use_operand_p use_p;
+ FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter)
+ {
+ if (gimple_code (use_stmt) == GIMPLE_PHI)
+ {
+ edge e = gimple_phi_arg_edge (as_a <gphi *> (use_stmt),
+ PHI_ARG_INDEX_FROM_USE (use_p));
+ use_bb = e->src;
+ }
+ find_uses_to_rename_use (use_bb, USE_FROM_PTR (use_p), use_blocks,
+ need_phis);
+ }
+ }
+}
+
+/* Marks names matching USE_FLAGS that are defined in LOOP and used outside of
+ it for rewrite. Records the set of blocks in which the ssa names are used to
+ USE_BLOCKS. Record the SSA names that will need exit PHIs in NEED_PHIS. */
+
+static void
+find_uses_to_rename_in_loop (struct loop *loop, bitmap *use_blocks,
+ bitmap need_phis, int use_flags)
+{
+ bool do_virtuals = (use_flags & SSA_OP_VIRTUAL_USES) != 0;
+ bool do_nonvirtuals = (use_flags & SSA_OP_USE) != 0;
+ int def_flags = ((do_virtuals ? SSA_OP_VIRTUAL_DEFS : 0)
+ | (do_nonvirtuals ? SSA_OP_DEF : 0));
+
+
+ basic_block *bbs = get_loop_body (loop);
+
+ for (unsigned int i = 0; i < loop->num_nodes; i++)
+ {
+ basic_block bb = bbs[i];
+
+ for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
+ gsi_next (&bsi))
+ {
+ gphi *phi = bsi.phi ();
+ tree res = gimple_phi_result (phi);
+ bool virtual_p = virtual_operand_p (res);
+ if ((virtual_p && do_virtuals)
+ || (!virtual_p && do_nonvirtuals))
+ find_uses_to_rename_def (res, use_blocks, need_phis);
+ }
+
+ for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
+ gsi_next (&bsi))
+ {
+ gimple stmt = gsi_stmt (bsi);
+ /* FOR_EACH_SSA_TREE_OPERAND iterator does not allows
+ SSA_OP_VIRTUAL_DEFS only. */
+ if (def_flags == SSA_OP_VIRTUAL_DEFS)
+ {
+ tree vdef = gimple_vdef (stmt);
+ if (vdef != NULL)
+ find_uses_to_rename_def (vdef, use_blocks, need_phis);
+ }
+ else
+ {
+ tree var;
+ ssa_op_iter iter;
+ FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, def_flags)
+ find_uses_to_rename_def (var, use_blocks, need_phis);
+ }
+ }
+ }
+
+ XDELETEVEC (bbs);