* [PATCH 0/6] use an helper to add an instruction to a BB
@ 2021-03-21 16:16 Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 1/6] add insert_last_instruction() Luc Van Oostenryck
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2021-03-21 16:16 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
This series adds and uses an new helper to add an instruction at
the end of a BB.
It's a preparatory step for incoming changes in memops simplifications.
Luc Van Oostenryck (6):
add insert_last_instruction()
replace add_instruction_to_end() by insert_last_instruction()
let insert_select() use insert_last_instruction()
let insert_phis() use insert_last_instruction()
let find_dominating_parents() use insert_last_instruction()
let ssa_rename_phi() use insert_last_instruction()
cse.c | 10 +---------
linearize.c | 14 ++++----------
linearize.h | 8 ++++++++
memops.c | 10 +++++-----
ssa.c | 6 +++---
5 files changed, 21 insertions(+), 27 deletions(-)
base-commit: 7b5cc7b6135733cbbce121cc94fdc4a5400f46b5
--
2.31.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] add insert_last_instruction()
2021-03-21 16:16 [PATCH 0/6] use an helper to add an instruction to a BB Luc Van Oostenryck
@ 2021-03-21 16:16 ` Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 2/6] replace add_instruction_to_end() by insert_last_instruction() Luc Van Oostenryck
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2021-03-21 16:16 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
It's relatively common to have to add an instruction at the end of a BB.
More exactly, at the end but just before the terminator instruction.
What is done for this is:
1) remove the terminator
2) add the new instruction
3) add the terminator back
This is a bit tedious, need to declare a temporary variable for the
terminator and, more generally, it's low-level details.
So, add an helper for doing this: insert_last_instruction().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/linearize.h b/linearize.h
index b6c8bf134065..493f6be1074c 100644
--- a/linearize.h
+++ b/linearize.h
@@ -195,6 +195,14 @@ static inline void add_instruction(struct instruction_list **list, struct instru
add_ptr_list(list, insn);
}
+static inline void insert_last_instruction(struct basic_block *bb, struct instruction *insn)
+{
+ struct instruction *last = delete_last_instruction(&bb->insns);
+ add_instruction(&bb->insns, insn);
+ add_instruction(&bb->insns, last);
+ insn->bb = bb;
+}
+
static inline void add_multijmp(struct multijmp_list **list, struct multijmp *multijmp)
{
add_ptr_list(list, multijmp);
--
2.31.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] replace add_instruction_to_end() by insert_last_instruction()
2021-03-21 16:16 [PATCH 0/6] use an helper to add an instruction to a BB Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 1/6] add insert_last_instruction() Luc Van Oostenryck
@ 2021-03-21 16:16 ` Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 3/6] let insert_select() use insert_last_instruction() Luc Van Oostenryck
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2021-03-21 16:16 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
add_instruction_to_end() and insert_last_instruction() do exactly
the same thing but with the arguments in the opposite order.
So, replace add_instruction_to_end() by insert_last_instruction().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
cse.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/cse.c b/cse.c
index 1e58a973ecf6..b59581814ab7 100644
--- a/cse.c
+++ b/cse.c
@@ -298,14 +298,6 @@ static inline void remove_instruction(struct instruction_list **list, struct ins
delete_ptr_list_entry((struct ptr_list **)list, insn, count);
}
-static void add_instruction_to_end(struct instruction *insn, struct basic_block *bb)
-{
- struct instruction *br = delete_last_instruction(&bb->insns);
- insn->bb = bb;
- add_instruction(&bb->insns, insn);
- add_instruction(&bb->insns, br);
-}
-
static struct instruction * try_to_cse(struct entrypoint *ep, struct instruction *i1, struct instruction *i2)
{
struct basic_block *b1, *b2, *common;
@@ -343,7 +335,7 @@ static struct instruction * try_to_cse(struct entrypoint *ep, struct instruction
if (common) {
i1 = cse_one_instruction(i2, i1);
remove_instruction(&b1->insns, i1, 1);
- add_instruction_to_end(i1, common);
+ insert_last_instruction(common, i1);
} else {
i1 = i2;
}
--
2.31.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] let insert_select() use insert_last_instruction()
2021-03-21 16:16 [PATCH 0/6] use an helper to add an instruction to a BB Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 1/6] add insert_last_instruction() Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 2/6] replace add_instruction_to_end() by insert_last_instruction() Luc Van Oostenryck
@ 2021-03-21 16:16 ` Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 4/6] let insert_phis() " Luc Van Oostenryck
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2021-03-21 16:16 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/linearize.c b/linearize.c
index e6aa01f1b9fe..4787689b37b8 100644
--- a/linearize.c
+++ b/linearize.c
@@ -697,11 +697,7 @@ void insert_select(struct basic_block *bb, struct instruction *br, struct instru
pseudo_t target;
struct instruction *select;
- /* Remove the 'br' */
- delete_last_instruction(&bb->insns);
-
select = alloc_typed_instruction(OP_SEL, phi_node->type);
- select->bb = bb;
assert(br->cond);
use_pseudo(select, br->cond, &select->src1);
@@ -714,8 +710,7 @@ void insert_select(struct basic_block *bb, struct instruction *br, struct instru
use_pseudo(select, if_true, &select->src2);
use_pseudo(select, if_false, &select->src3);
- add_instruction(&bb->insns, select);
- add_instruction(&bb->insns, br);
+ insert_last_instruction(bb, select);
}
static inline int bb_empty(struct basic_block *bb)
--
2.31.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] let insert_phis() use insert_last_instruction()
2021-03-21 16:16 [PATCH 0/6] use an helper to add an instruction to a BB Luc Van Oostenryck
` (2 preceding siblings ...)
2021-03-21 16:16 ` [PATCH 3/6] let insert_select() use insert_last_instruction() Luc Van Oostenryck
@ 2021-03-21 16:16 ` Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 5/6] let find_dominating_parents() " Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 6/6] let ssa_rename_phi() " Luc Van Oostenryck
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2021-03-21 16:16 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/linearize.c b/linearize.c
index 4787689b37b8..95fb3b59b90b 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1708,10 +1708,9 @@ static void insert_phis(struct basic_block *bb, pseudo_t src, struct symbol *cty
struct basic_block *parent;
FOR_EACH_PTR(bb->parents, parent) {
- struct instruction *br = delete_last_instruction(&parent->insns);
- pseudo_t phi = alloc_phi(parent, src, ctype);
- add_instruction(&parent->insns, br);
- link_phi(node, phi);
+ struct instruction *phisrc = alloc_phisrc(src, ctype);
+ insert_last_instruction(parent, phisrc);
+ link_phi(node, phisrc->target);
} END_FOR_EACH_PTR(parent);
}
--
2.31.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] let find_dominating_parents() use insert_last_instruction()
2021-03-21 16:16 [PATCH 0/6] use an helper to add an instruction to a BB Luc Van Oostenryck
` (3 preceding siblings ...)
2021-03-21 16:16 ` [PATCH 4/6] let insert_phis() " Luc Van Oostenryck
@ 2021-03-21 16:16 ` Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 6/6] let ssa_rename_phi() " Luc Van Oostenryck
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2021-03-21 16:16 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
memops.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/memops.c b/memops.c
index ff54208e2d54..f74bff2abf88 100644
--- a/memops.c
+++ b/memops.c
@@ -65,8 +65,8 @@ static int find_dominating_parents(pseudo_t pseudo, struct instruction *insn,
struct basic_block *parent;
FOR_EACH_PTR(bb->parents, parent) {
+ struct instruction *phisrc;
struct instruction *one;
- struct instruction *br;
pseudo_t phi;
FOR_EACH_PTR_REVERSE(parent->insns, one) {
@@ -95,12 +95,12 @@ no_dominance:
continue;
found_dominator:
- br = delete_last_instruction(&parent->insns);
- phi = alloc_phi(parent, one->target, one->type);
+ phisrc = alloc_phisrc(one->target, one->type);
+ phisrc->phi_node = insn;
+ insert_last_instruction(parent, phisrc);
+ phi = phisrc->target;
phi->ident = phi->ident ? : one->target->ident;
- add_instruction(&parent->insns, br);
use_pseudo(insn, phi, add_pseudo(dominators, phi));
- phi->def->phi_node = insn;
} END_FOR_EACH_PTR(parent);
return 1;
}
--
2.31.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] let ssa_rename_phi() use insert_last_instruction()
2021-03-21 16:16 [PATCH 0/6] use an helper to add an instruction to a BB Luc Van Oostenryck
` (4 preceding siblings ...)
2021-03-21 16:16 ` [PATCH 5/6] let find_dominating_parents() " Luc Van Oostenryck
@ 2021-03-21 16:16 ` Luc Van Oostenryck
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2021-03-21 16:16 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
ssa.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ssa.c b/ssa.c
index b9044207db16..5f1a52b8fe94 100644
--- a/ssa.c
+++ b/ssa.c
@@ -345,11 +345,11 @@ static void ssa_rename_phi(struct instruction *insn)
if (!var->torename)
return;
FOR_EACH_PTR(insn->bb->parents, par) {
- struct instruction *term = delete_last_instruction(&par->insns);
pseudo_t val = lookup_var(par, var);
- pseudo_t phi = alloc_phi(par, val, var);
+ struct instruction *phisrc = alloc_phisrc(val, var);
+ pseudo_t phi = phisrc->target;
phi->ident = var->ident;
- add_instruction(&par->insns, term);
+ insert_last_instruction(par, phisrc);
link_phi(insn, phi);
mark_phi_used(val);
} END_FOR_EACH_PTR(par);
--
2.31.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-03-21 16:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 16:16 [PATCH 0/6] use an helper to add an instruction to a BB Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 1/6] add insert_last_instruction() Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 2/6] replace add_instruction_to_end() by insert_last_instruction() Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 3/6] let insert_select() use insert_last_instruction() Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 4/6] let insert_phis() " Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 5/6] let find_dominating_parents() " Luc Van Oostenryck
2021-03-21 16:16 ` [PATCH 6/6] let ssa_rename_phi() " Luc Van Oostenryck
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).