aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-cfg.cc
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2023-05-02 16:04:00 -0700
committerAndrew Pinski <apinski@marvell.com>2023-05-04 04:25:27 -0700
commit78b0eea7802698f51377f77aa98453556854a328 (patch)
tree68de52bf3d6359215b071ff6c5ae394fc7dbd687 /gcc/tree-cfg.cc
parent8830e46777407a7d5cd3de353394ffc46f2c785c (diff)
downloadgcc-78b0eea7802698f51377f77aa98453556854a328.zip
gcc-78b0eea7802698f51377f77aa98453556854a328.tar.gz
gcc-78b0eea7802698f51377f77aa98453556854a328.tar.bz2
Move copy_phi_arg_into_existing_phi to common location and use it
While improving replace_phi_edge_with_variable for the diamond formed bb case, I need a way to copy phi entries from one edge to another as I am removing a forwarding bb inbetween. I was pointed out that jump threading code had copy_phi_arg_into_existing_phi which I can use. I also noticed that both gimple_duplicate_sese_tail and remove_forwarder_block have similar code so it makes sense to use that function in those two locations too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-threadupdate.cc (copy_phi_arg_into_existing_phi): Move to ... * tree-cfg.cc (copy_phi_arg_into_existing_phi): Here and remove static. (gimple_duplicate_sese_tail): Use copy_phi_arg_into_existing_phi instead of an inline version of it. * tree-cfgcleanup.cc (remove_forwarder_block): Likewise. * tree-cfg.h (copy_phi_arg_into_existing_phi): New declaration.
Diffstat (limited to 'gcc/tree-cfg.cc')
-rw-r--r--gcc/tree-cfg.cc38
1 files changed, 27 insertions, 11 deletions
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 21cf6fc..0aeebb6 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -6802,6 +6802,32 @@ bb_part_of_region_p (basic_block bb, basic_block* bbs, unsigned n_region)
return false;
}
+
+/* For each PHI in BB, copy the argument associated with SRC_E to TGT_E.
+ Assuming the argument exists, just does not have a value. */
+
+void
+copy_phi_arg_into_existing_phi (edge src_e, edge tgt_e)
+{
+ int src_idx = src_e->dest_idx;
+ int tgt_idx = tgt_e->dest_idx;
+
+ /* Iterate over each PHI in e->dest. */
+ for (gphi_iterator gsi = gsi_start_phis (src_e->dest),
+ gsi2 = gsi_start_phis (tgt_e->dest);
+ !gsi_end_p (gsi);
+ gsi_next (&gsi), gsi_next (&gsi2))
+ {
+ gphi *src_phi = gsi.phi ();
+ gphi *dest_phi = gsi2.phi ();
+ tree val = gimple_phi_arg_def (src_phi, src_idx);
+ location_t locus = gimple_phi_arg_location (src_phi, src_idx);
+
+ SET_PHI_ARG_DEF (dest_phi, tgt_idx, val);
+ gimple_phi_arg_set_location (dest_phi, tgt_idx, locus);
+ }
+}
+
/* Duplicates REGION consisting of N_REGION blocks. The new blocks
are stored to REGION_COPY in the same order in that they appear
in REGION, if REGION_COPY is not NULL. ENTRY is the entry to
@@ -6847,9 +6873,6 @@ gimple_duplicate_sese_tail (edge entry, edge exit,
gimple_stmt_iterator gsi;
edge sorig, snew;
basic_block exit_bb;
- gphi_iterator psi;
- gphi *phi;
- tree def;
class loop *target, *aloop, *cloop;
gcc_assert (EDGE_COUNT (exit->src->succs) == 2);
@@ -6947,14 +6970,7 @@ gimple_duplicate_sese_tail (edge entry, edge exit,
gcc_assert (single_succ_edge (region_copy[i]));
e = redirect_edge_and_branch (single_succ_edge (region_copy[i]), exit_bb);
PENDING_STMT (e) = NULL;
- for (psi = gsi_start_phis (exit_bb);
- !gsi_end_p (psi);
- gsi_next (&psi))
- {
- phi = psi.phi ();
- def = PHI_ARG_DEF (phi, nexits[0]->dest_idx);
- add_phi_arg (phi, def, e, gimple_phi_arg_location_from_edge (phi, e));
- }
+ copy_phi_arg_into_existing_phi (nexits[0], e);
}
e = redirect_edge_and_branch (nexits[1], nexits[0]->dest);
PENDING_STMT (e) = NULL;