linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 10/13] add remove_phisources()
Date: Sun, 21 Mar 2021 13:35:02 +0100	[thread overview]
Message-ID: <20210321123505.27993-11-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com>

When a parent is removed from a BB containing one or several phi-nodes,
the corresponding phi-sources become irrelevant and need to be removed
from the phi-nodes.

Add an helper for doing this: remove_phisources().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 flow.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 flow.h |  2 ++
 2 files changed, 45 insertions(+)

diff --git a/flow.c b/flow.c
index 8106cfc0d10b..4952562a373d 100644
--- a/flow.c
+++ b/flow.c
@@ -22,6 +22,49 @@
 
 unsigned long bb_generation;
 
+///
+// remove phi-sources from a removed edge
+//
+// :note: It's possible to have several edges between the same BBs.
+//	  It's common with switches but it's also possible with branches.
+//	  This function will only remove a single phi-source per edge.
+int remove_phisources(struct basic_block *par, struct basic_block *old)
+{
+	struct instruction *insn;
+	int changed = 0;
+
+	FOR_EACH_PTR(old->insns, insn) {
+		pseudo_t phi;
+
+		if (!insn->bb)
+			continue;
+		if (insn->opcode != OP_PHI)
+			return changed;
+
+		// found a phi-node in the target BB,
+		// now look after its phi-sources.
+		FOR_EACH_PTR(insn->phi_list, phi) {
+			struct instruction *phisrc = phi->def;
+
+			if (phi == VOID)
+				continue;
+			assert(phisrc->phi_node == insn);
+			if (phisrc->bb != par)
+				continue;
+			// found a phi-source corresponding to this edge:
+			// remove it but avoid the recursive killing.
+			REPLACE_CURRENT_PTR(phi, VOID);
+			remove_use(&phisrc->src);
+			phisrc->bb = NULL;
+			changed |= REPEAT_CSE;
+			// Only the first one must be removed.
+			goto next;
+		} END_FOR_EACH_PTR(phi);
+next: ;
+	} END_FOR_EACH_PTR(insn);
+	return changed;
+}
+
 /*
  * Dammit, if we have a phi-node followed by a conditional
  * branch on that phi-node, we should damn well be able to
diff --git a/flow.h b/flow.h
index 2103a10fe428..c489ebe03034 100644
--- a/flow.h
+++ b/flow.h
@@ -11,6 +11,8 @@ extern unsigned long bb_generation;
 struct entrypoint;
 struct instruction;
 
+extern int remove_phisources(struct basic_block *par, struct basic_block *old);
+
 extern int simplify_flow(struct entrypoint *ep);
 
 extern void kill_dead_stores(struct entrypoint *ep, pseudo_t addr, int local);
-- 
2.31.0


  parent reply	other threads:[~2021-03-21 12:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-21 12:34 [PATCH 00/13] remove phi-sources from removed branches Luc Van Oostenryck
2021-03-21 12:34 ` [PATCH 01/13] Revert "simplify CBR-CBR on the same condition" Luc Van Oostenryck
2021-03-21 12:34 ` [PATCH 02/13] add testcases to check if phi-sources from removed targets are removed too Luc Van Oostenryck
2021-03-21 12:34 ` [PATCH 03/13] remove insert_branch() redundant arg Luc Van Oostenryck
2021-03-21 12:34 ` [PATCH 04/13] simplify remove_parent() Luc Van Oostenryck
2021-03-21 12:34 ` [PATCH 05/13] fold remove_parent() into insert_branch() Luc Van Oostenryck
2021-03-21 12:34 ` [PATCH 06/13] let insert_branch() reuse the terminating instruction Luc Van Oostenryck
2021-03-21 12:34 ` [PATCH 07/13] move insert_branch() to flow.c Luc Van Oostenryck
2021-03-21 12:35 ` [PATCH 08/13] let insert_branch() return a status Luc Van Oostenryck
2021-03-21 12:35 ` [PATCH 09/13] rename insert_branch() to convert_to_jump() Luc Van Oostenryck
2021-03-21 12:35 ` Luc Van Oostenryck [this message]
2021-03-21 12:35 ` [PATCH 11/13] fix phisources during CBR-BR conversion Luc Van Oostenryck
2021-03-21 12:35 ` [PATCH 12/13] use convert_to_jump() when converting a CBR with same targets Luc Van Oostenryck
2021-03-21 12:35 ` [PATCH 13/13] fix phisources during SWITCH-BR conversion Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210321123505.27993-11-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).