All of lore.kernel.org
 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 07/13] move insert_branch() to flow.c
Date: Sun, 21 Mar 2021 13:34:59 +0100	[thread overview]
Message-ID: <20210321123505.27993-8-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20210321123505.27993-1-luc.vanoostenryck@gmail.com>

Now that insert_branch() doesn't need to allocate a new instruction,
there is no more reasons to have it defined in linearize.c

So move it to flow.c which is more concerned with CFG changes.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 flow.c      | 26 ++++++++++++++++++++++++++
 flow.h      |  1 +
 linearize.c | 26 --------------------------
 linearize.h |  1 -
 4 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/flow.c b/flow.c
index f85c2a30c3cb..1f4b4ff08151 100644
--- a/flow.c
+++ b/flow.c
@@ -709,6 +709,32 @@ void vrfy_flow(struct entrypoint *ep)
 	assert(!entry);
 }
 
+///
+// change a switch or a conditional branch into a branch
+void insert_branch(struct instruction *insn, struct basic_block *target)
+{
+	struct basic_block *bb = insn->bb;
+	struct basic_block *child;
+
+	kill_use(&insn->cond);
+	insn->bb_true = target;
+	insn->bb_false = NULL;
+	insn->cond = NULL;
+	insn->size = 0;
+	insn->opcode = OP_BR;
+
+	FOR_EACH_PTR(bb->children, child) {
+		if (child == target) {
+			target = NULL;	// leave first occurence
+			continue;
+		}
+		DELETE_CURRENT_PTR(child);
+		remove_bb_from_list(&child->parents, bb, 1);
+	} END_FOR_EACH_PTR(child);
+	PACK_PTR_LIST(&bb->children);
+	repeat_phase |= REPEAT_CFG_CLEANUP;
+}
+
 static int retarget_parents(struct basic_block *bb, struct basic_block *target)
 {
 	struct basic_block *parent;
diff --git a/flow.h b/flow.h
index 46d76a780484..f9213306dfd6 100644
--- a/flow.h
+++ b/flow.h
@@ -18,6 +18,7 @@ extern void simplify_symbol_usage(struct entrypoint *ep);
 extern void simplify_memops(struct entrypoint *ep);
 extern void pack_basic_blocks(struct entrypoint *ep);
 extern int simplify_cfg_early(struct entrypoint *ep);
+extern void insert_branch(struct instruction *insn, struct basic_block *target);
 
 extern void convert_instruction_target(struct instruction *insn, pseudo_t src);
 extern void remove_dead_insns(struct entrypoint *);
diff --git a/linearize.c b/linearize.c
index 1d85cf2ba208..e6aa01f1b9fe 100644
--- a/linearize.c
+++ b/linearize.c
@@ -692,32 +692,6 @@ static void set_activeblock(struct entrypoint *ep, struct basic_block *bb)
 		add_bb(&ep->bbs, bb);
 }
 
-/* Change a "switch" or a conditional branch into a branch */
-void insert_branch(struct instruction *jmp, struct basic_block *target)
-{
-	struct basic_block *bb = jmp->bb;
-	struct basic_block *child;
-
-	kill_use(&jmp->cond);
-	jmp->bb_true = target;
-	jmp->bb_false = NULL;
-	jmp->cond = NULL;
-	jmp->size = 0;
-	jmp->opcode = OP_BR;
-
-	FOR_EACH_PTR(bb->children, child) {
-		if (child == target) {
-			target = NULL;	/* Trigger just once */
-			continue;
-		}
-		DELETE_CURRENT_PTR(child);
-		remove_bb_from_list(&child->parents, bb, 1);
-	} END_FOR_EACH_PTR(child);
-	PACK_PTR_LIST(&bb->children);
-	repeat_phase |= REPEAT_CFG_CLEANUP;
-}
-	
-
 void insert_select(struct basic_block *bb, struct instruction *br, struct instruction *phi_node, pseudo_t if_true, pseudo_t if_false)
 {
 	pseudo_t target;
diff --git a/linearize.h b/linearize.h
index 1bb9d77eba1f..b6c8bf134065 100644
--- a/linearize.h
+++ b/linearize.h
@@ -319,7 +319,6 @@ struct entrypoint {
 };
 
 extern void insert_select(struct basic_block *bb, struct instruction *br, struct instruction *phi, pseudo_t if_true, pseudo_t if_false);
-extern void insert_branch(struct instruction *br, struct basic_block *target);
 
 struct instruction *alloc_phisrc(pseudo_t pseudo, struct symbol *type);
 struct instruction *alloc_phi_node(struct basic_block *bb, struct symbol *type, struct ident *ident);
-- 
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 ` Luc Van Oostenryck [this message]
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 ` [PATCH 10/13] add remove_phisources() Luc Van Oostenryck
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-8-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.