public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/pheeck/heads/sccp)] sccp now actually replaces phis with values
@ 2022-09-02 15:31 Filip Kastl
0 siblings, 0 replies; 2+ messages in thread
From: Filip Kastl @ 2022-09-02 15:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c798727d40ceb10337f785c448d07e62c184513c
commit c798727d40ceb10337f785c448d07e62c184513c
Author: Filip Kastl <filip.kastl@gmail.com>
Date: Fri Sep 2 17:31:36 2022 +0200
sccp now actually replaces phis with values
Diff:
---
gcc/sccp.cc | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/gcc/sccp.cc b/gcc/sccp.cc
index 8b57e3a4a3c..a4b332e0c29 100644
--- a/gcc/sccp.cc
+++ b/gcc/sccp.cc
@@ -320,14 +320,43 @@ replace_scc_by_value (vec<gphi *> scc, tree v)
{
for (gphi *phi : scc)
{
- // DEBUG
tree ssa_name = gimple_get_lhs (phi);
+
+ // DEBUG
unsigned vnum_get_replaced = SSA_NAME_VERSION (ssa_name);
unsigned vnum_replaced_by = SSA_NAME_VERSION (v);
std::cerr << "Replacing " << vnum_get_replaced << " by " <<
vnum_replaced_by << std::endl;
- // TODO Remove phi statement and free ssa name
- // TODO Replace occurences of phi with v
+
+ /* Replace each occurence of phi by value v. */
+ use_operand_p use_p;
+ imm_use_iterator iter;
+ gimple *use_stmt;
+ FOR_EACH_IMM_USE_STMT (use_stmt, iter, ssa_name)
+ FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
+ SET_USE (use_p, v);
+ }
+}
+
+/* Remove all PHIs with zero uses. */
+
+static void
+remove_zero_uses_phis ()
+{
+ basic_block bb;
+ FOR_EACH_BB_FN (bb, cfun)
+ {
+ gphi_iterator pi;
+ for (pi = gsi_start_phis (bb); !gsi_end_p (pi);)
+ {
+ gphi *phi = pi.phi ();
+ tree ssa_name = gimple_phi_result (phi);
+ if (has_zero_uses (ssa_name))
+ /* Note that remove_phi_node() also frees SSA name. */
+ remove_phi_node (&pi, true);
+ else
+ gsi_next (&pi);
+ }
}
}
@@ -393,6 +422,7 @@ remove_redundant_phis (vec<gphi *> phis)
{
process_scc (scc);
}
+ remove_zero_uses_phis ();
}
/* TODO Pass description. */
^ permalink raw reply [flat|nested] 2+ messages in thread
* [gcc(refs/users/pheeck/heads/sccp)] sccp now actually replaces phis with values
@ 2023-02-15 10:14 Filip Kastl
0 siblings, 0 replies; 2+ messages in thread
From: Filip Kastl @ 2023-02-15 10:14 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:567c65dc2ce024f2a45189e74f1a17fed0a8e06b
commit 567c65dc2ce024f2a45189e74f1a17fed0a8e06b
Author: Filip Kastl <filip.kastl@gmail.com>
Date: Fri Sep 2 17:31:36 2022 +0200
sccp now actually replaces phis with values
Diff:
---
gcc/sccp.cc | 36 +++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/gcc/sccp.cc b/gcc/sccp.cc
index 8b57e3a4a3c..a4b332e0c29 100644
--- a/gcc/sccp.cc
+++ b/gcc/sccp.cc
@@ -320,14 +320,43 @@ replace_scc_by_value (vec<gphi *> scc, tree v)
{
for (gphi *phi : scc)
{
- // DEBUG
tree ssa_name = gimple_get_lhs (phi);
+
+ // DEBUG
unsigned vnum_get_replaced = SSA_NAME_VERSION (ssa_name);
unsigned vnum_replaced_by = SSA_NAME_VERSION (v);
std::cerr << "Replacing " << vnum_get_replaced << " by " <<
vnum_replaced_by << std::endl;
- // TODO Remove phi statement and free ssa name
- // TODO Replace occurences of phi with v
+
+ /* Replace each occurence of phi by value v. */
+ use_operand_p use_p;
+ imm_use_iterator iter;
+ gimple *use_stmt;
+ FOR_EACH_IMM_USE_STMT (use_stmt, iter, ssa_name)
+ FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
+ SET_USE (use_p, v);
+ }
+}
+
+/* Remove all PHIs with zero uses. */
+
+static void
+remove_zero_uses_phis ()
+{
+ basic_block bb;
+ FOR_EACH_BB_FN (bb, cfun)
+ {
+ gphi_iterator pi;
+ for (pi = gsi_start_phis (bb); !gsi_end_p (pi);)
+ {
+ gphi *phi = pi.phi ();
+ tree ssa_name = gimple_phi_result (phi);
+ if (has_zero_uses (ssa_name))
+ /* Note that remove_phi_node() also frees SSA name. */
+ remove_phi_node (&pi, true);
+ else
+ gsi_next (&pi);
+ }
}
}
@@ -393,6 +422,7 @@ remove_redundant_phis (vec<gphi *> phis)
{
process_scc (scc);
}
+ remove_zero_uses_phis ();
}
/* TODO Pass description. */
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-15 10:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-02 15:31 [gcc(refs/users/pheeck/heads/sccp)] sccp now actually replaces phis with values Filip Kastl
2023-02-15 10:14 Filip Kastl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).