* [PATCH 0/5] use replace_with_pseudo() for simplify_memops()
@ 2020-11-29 14:49 Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 1/5] let replace_with_pseudo() use kill_instruction() Luc Van Oostenryck
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2020-11-29 14:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
This series contains a few patches related to replace_with_pseudo()
in preparation for some more consequential changes in memops
simplification.
Luc Van Oostenryck (5):
let replace_with_pseudo() use kill_instruction()
make a header for simplification
make replace_with_pseudo() extern
memops: move rewrite_load_instruction() here
replace convert_load_instruction() by replace_with_pseudo()
flow.c | 48 +-----------------------------------------------
flow.h | 3 ---
memops.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
optimize.c | 1 +
simplify.c | 21 +++------------------
simplify.h | 10 ++++++++++
ssa.c | 9 +++++----
7 files changed, 64 insertions(+), 74 deletions(-)
create mode 100644 simplify.h
--
2.29.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] let replace_with_pseudo() use kill_instruction()
2020-11-29 14:49 [PATCH 0/5] use replace_with_pseudo() for simplify_memops() Luc Van Oostenryck
@ 2020-11-29 14:49 ` Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 2/5] make a header for simplification Luc Van Oostenryck
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2020-11-29 14:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
In replace_with_pseudo(), the replaced instruction needs to be killed
and for this contains ts own code.
But this is a duplication of what is already done in kill_instruction().
So, replace this part of the code by a cal to kill_instruction().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 18 +-----------------
1 file changed, 1 insertion(+), 17 deletions(-)
diff --git a/simplify.c b/simplify.c
index de03d315ec33..29b368e94ff4 100644
--- a/simplify.c
+++ b/simplify.c
@@ -445,23 +445,7 @@ static inline int replace_pseudo(struct instruction *insn, pseudo_t *pp, pseudo_
static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo)
{
convert_instruction_target(insn, pseudo);
-
- switch (insn->opcode) {
- case OP_SEL:
- case OP_RANGE:
- kill_use(&insn->src3);
- case OP_BINARY ... OP_BINCMP_END:
- kill_use(&insn->src2);
- case OP_UNOP ... OP_UNOP_END:
- case OP_SYMADDR:
- kill_use(&insn->src1);
- break;
-
- default:
- assert(0);
- }
- insn->bb = NULL;
- return REPEAT_CSE;
+ return kill_instruction(insn);
}
static inline int replace_with_value(struct instruction *insn, long long val)
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/5] make a header for simplification
2020-11-29 14:49 [PATCH 0/5] use replace_with_pseudo() for simplify_memops() Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 1/5] let replace_with_pseudo() use kill_instruction() Luc Van Oostenryck
@ 2020-11-29 14:49 ` Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 3/5] make replace_with_pseudo() extern Luc Van Oostenryck
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2020-11-29 14:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
The few external functions defined in simplify.h are declared
in flow.h (for historical reasons).
In preparation for some changes, create a specific headers for these.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
flow.h | 1 -
optimize.c | 1 +
simplify.c | 1 +
simplify.h | 8 ++++++++
4 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 simplify.h
diff --git a/flow.h b/flow.h
index c3461c8c33bd..7cdc7c2a496b 100644
--- a/flow.h
+++ b/flow.h
@@ -21,7 +21,6 @@ extern int simplify_cfg_early(struct entrypoint *ep);
extern void convert_instruction_target(struct instruction *insn, pseudo_t src);
extern void remove_dead_insns(struct entrypoint *);
-extern int simplify_instruction(struct instruction *);
extern void kill_bb(struct basic_block *);
extern void kill_use(pseudo_t *);
diff --git a/optimize.c b/optimize.c
index 9b754831f8b0..3351e67b9d5e 100644
--- a/optimize.c
+++ b/optimize.c
@@ -12,6 +12,7 @@
#include "flowgraph.h"
#include "linearize.h"
#include "liveness.h"
+#include "simplify.h"
#include "flow.h"
#include "cse.h"
#include "ir.h"
diff --git a/simplify.c b/simplify.c
index 29b368e94ff4..69eae4f8a5a1 100644
--- a/simplify.c
+++ b/simplify.c
@@ -44,6 +44,7 @@
#include "parse.h"
#include "expression.h"
#include "linearize.h"
+#include "simplify.h"
#include "flow.h"
#include "symbol.h"
diff --git a/simplify.h b/simplify.h
new file mode 100644
index 000000000000..200d79c00a83
--- /dev/null
+++ b/simplify.h
@@ -0,0 +1,8 @@
+#ifndef SIMPLIFY_H
+#define SIMPLIFY_H
+
+#include "linearize.h"
+
+int simplify_instruction(struct instruction *insn);
+
+#endif
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] make replace_with_pseudo() extern
2020-11-29 14:49 [PATCH 0/5] use replace_with_pseudo() for simplify_memops() Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 1/5] let replace_with_pseudo() use kill_instruction() Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 2/5] make a header for simplification Luc Van Oostenryck
@ 2020-11-29 14:49 ` Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 4/5] memops: move rewrite_load_instruction() here Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 5/5] replace convert_load_instruction() by replace_with_pseudo() Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2020-11-29 14:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
This function can be useful since it can be useful in other files,
for example in memops.c
So make it extern..
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 2 +-
simplify.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/simplify.c b/simplify.c
index 69eae4f8a5a1..2c587bea3a8a 100644
--- a/simplify.c
+++ b/simplify.c
@@ -443,7 +443,7 @@ static inline int replace_pseudo(struct instruction *insn, pseudo_t *pp, pseudo_
return REPEAT_CSE;
}
-static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo)
+int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo)
{
convert_instruction_target(insn, pseudo);
return kill_instruction(insn);
diff --git a/simplify.h b/simplify.h
index 200d79c00a83..ed3dd9716a3e 100644
--- a/simplify.h
+++ b/simplify.h
@@ -5,4 +5,6 @@
int simplify_instruction(struct instruction *insn);
+int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo);
+
#endif
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] memops: move rewrite_load_instruction() here
2020-11-29 14:49 [PATCH 0/5] use replace_with_pseudo() for simplify_memops() Luc Van Oostenryck
` (2 preceding siblings ...)
2020-11-29 14:49 ` [PATCH 3/5] make replace_with_pseudo() extern Luc Van Oostenryck
@ 2020-11-29 14:49 ` Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 5/5] replace convert_load_instruction() by replace_with_pseudo() Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2020-11-29 14:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
The function rewrite_load_instruction() is defined in flow.c but:
* is not directly related to 'flow'
* it's only used in memops.c
* needs some change related to simplify_loads().
So, move this code to memops.c
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
flow.c | 41 -----------------------------------------
flow.h | 1 -
memops.c | 41 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 42 deletions(-)
diff --git a/flow.c b/flow.c
index 1a871df16bd5..20827acce88b 100644
--- a/flow.c
+++ b/flow.c
@@ -520,47 +520,6 @@ int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom
return 1;
}
-/*
- * We should probably sort the phi list just to make it easier to compare
- * later for equality.
- */
-void rewrite_load_instruction(struct instruction *insn, struct pseudo_list *dominators)
-{
- pseudo_t new, phi;
-
- /*
- * Check for somewhat common case of duplicate
- * phi nodes.
- */
- new = first_pseudo(dominators)->def->phi_src;
- FOR_EACH_PTR(dominators, phi) {
- if (new != phi->def->phi_src)
- goto complex_phi;
- new->ident = new->ident ? : phi->ident;
- } END_FOR_EACH_PTR(phi);
-
- /*
- * All the same pseudo - mark the phi-nodes unused
- * and convert the load into a LNOP and replace the
- * pseudo.
- */
- convert_load_instruction(insn, new);
- FOR_EACH_PTR(dominators, phi) {
- kill_instruction(phi->def);
- } END_FOR_EACH_PTR(phi);
- goto end;
-
-complex_phi:
- /* We leave symbol pseudos with a bogus usage list here */
- if (insn->src->type != PSEUDO_SYM)
- kill_use(&insn->src);
- insn->opcode = OP_PHI;
- insn->phi_list = dominators;
-
-end:
- repeat_phase |= REPEAT_CSE;
-}
-
/* Kill a pseudo that is dead on exit from the bb */
// The context is:
// * the variable is not global but may have its address used (local/non-local)
diff --git a/flow.h b/flow.h
index 7cdc7c2a496b..c55362de848e 100644
--- a/flow.h
+++ b/flow.h
@@ -39,7 +39,6 @@ static inline int kill_instruction_force(struct instruction *insn)
void check_access(struct instruction *insn);
void convert_load_instruction(struct instruction *, pseudo_t);
-void rewrite_load_instruction(struct instruction *, struct pseudo_list *);
int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom, int local);
extern void vrfy_flow(struct entrypoint *ep);
diff --git a/memops.c b/memops.c
index badcdbbb9378..6620688264ad 100644
--- a/memops.c
+++ b/memops.c
@@ -16,6 +16,47 @@
#include "linearize.h"
#include "flow.h"
+/*
+ * We should probably sort the phi list just to make it easier to compare
+ * later for equality.
+ */
+static void rewrite_load_instruction(struct instruction *insn, struct pseudo_list *dominators)
+{
+ pseudo_t new, phi;
+
+ /*
+ * Check for somewhat common case of duplicate
+ * phi nodes.
+ */
+ new = first_pseudo(dominators)->def->phi_src;
+ FOR_EACH_PTR(dominators, phi) {
+ if (new != phi->def->phi_src)
+ goto complex_phi;
+ new->ident = new->ident ? : phi->ident;
+ } END_FOR_EACH_PTR(phi);
+
+ /*
+ * All the same pseudo - mark the phi-nodes unused
+ * and convert the load into a LNOP and replace the
+ * pseudo.
+ */
+ convert_load_instruction(insn, new);
+ FOR_EACH_PTR(dominators, phi) {
+ kill_instruction(phi->def);
+ } END_FOR_EACH_PTR(phi);
+ goto end;
+
+complex_phi:
+ /* We leave symbol pseudos with a bogus usage list here */
+ if (insn->src->type != PSEUDO_SYM)
+ kill_use(&insn->src);
+ insn->opcode = OP_PHI;
+ insn->phi_list = dominators;
+
+end:
+ repeat_phase |= REPEAT_CSE;
+}
+
static int find_dominating_parents(pseudo_t pseudo, struct instruction *insn,
struct basic_block *bb, unsigned long generation, struct pseudo_list **dominators,
int local)
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/5] replace convert_load_instruction() by replace_with_pseudo()
2020-11-29 14:49 [PATCH 0/5] use replace_with_pseudo() for simplify_memops() Luc Van Oostenryck
` (3 preceding siblings ...)
2020-11-29 14:49 ` [PATCH 4/5] memops: move rewrite_load_instruction() here Luc Van Oostenryck
@ 2020-11-29 14:49 ` Luc Van Oostenryck
4 siblings, 0 replies; 6+ messages in thread
From: Luc Van Oostenryck @ 2020-11-29 14:49 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
These two functions are now exactly the same, so replace the
first one by the second one.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
flow.c | 7 +------
flow.h | 1 -
memops.c | 7 ++++---
ssa.c | 9 +++++----
4 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/flow.c b/flow.c
index 20827acce88b..95e44ac104f6 100644
--- a/flow.c
+++ b/flow.c
@@ -16,6 +16,7 @@
#include "parse.h"
#include "expression.h"
#include "linearize.h"
+#include "simplify.h"
#include "flow.h"
#include "target.h"
#include "flowgraph.h"
@@ -453,12 +454,6 @@ void convert_instruction_target(struct instruction *insn, pseudo_t src)
target->users = NULL;
}
-void convert_load_instruction(struct instruction *insn, pseudo_t src)
-{
- convert_instruction_target(insn, src);
- kill_instruction(insn);
-}
-
static int overlapping_memop(struct instruction *a, struct instruction *b)
{
unsigned int a_start = bytes_to_bits(a->offset);
diff --git a/flow.h b/flow.h
index c55362de848e..46d76a780484 100644
--- a/flow.h
+++ b/flow.h
@@ -38,7 +38,6 @@ static inline int kill_instruction_force(struct instruction *insn)
}
void check_access(struct instruction *insn);
-void convert_load_instruction(struct instruction *, pseudo_t);
int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom, int local);
extern void vrfy_flow(struct entrypoint *ep);
diff --git a/memops.c b/memops.c
index 6620688264ad..7efade22c9b5 100644
--- a/memops.c
+++ b/memops.c
@@ -14,6 +14,7 @@
#include "parse.h"
#include "expression.h"
#include "linearize.h"
+#include "simplify.h"
#include "flow.h"
/*
@@ -40,7 +41,7 @@ static void rewrite_load_instruction(struct instruction *insn, struct pseudo_lis
* and convert the load into a LNOP and replace the
* pseudo.
*/
- convert_load_instruction(insn, new);
+ replace_with_pseudo(insn, new);
FOR_EACH_PTR(dominators, phi) {
kill_instruction(phi->def);
} END_FOR_EACH_PTR(phi);
@@ -167,7 +168,7 @@ static void simplify_loads(struct basic_block *bb)
if (!compatible_loads(insn, dom))
goto next_load;
/* Yeehaa! Found one! */
- convert_load_instruction(insn, dom->target);
+ replace_with_pseudo(insn, dom->target);
goto next_load;
}
} END_FOR_EACH_PTR_REVERSE(dom);
@@ -181,7 +182,7 @@ static void simplify_loads(struct basic_block *bb)
if (!dominators) {
if (local) {
assert(pseudo->type != PSEUDO_ARG);
- convert_load_instruction(insn, value_pseudo(0));
+ replace_with_pseudo(insn, value_pseudo(0));
}
goto next_load;
}
diff --git a/ssa.c b/ssa.c
index 3e8800507f63..a2e27030e4b6 100644
--- a/ssa.c
+++ b/ssa.c
@@ -11,7 +11,8 @@
#include "dominate.h"
#include "flowgraph.h"
#include "linearize.h"
-#include "flow.h" // for convert_load_instruction()
+#include "simplify.h"
+#include "flow.h"
// Is it possible and desirable for this to be promoted to a pseudo?
@@ -109,7 +110,7 @@ static void rewrite_local_var(struct basic_block *bb, pseudo_t addr, int nbr_sto
case OP_LOAD:
if (!val)
val = undef_pseudo();
- convert_load_instruction(insn, val);
+ replace_with_pseudo(insn, val);
break;
case OP_STORE:
val = insn->target;
@@ -150,7 +151,7 @@ static bool rewrite_single_store(struct instruction *store)
// undefs ?
- convert_load_instruction(insn, store->target);
+ replace_with_pseudo(insn, store->target);
} END_FOR_EACH_PTR(pu);
// is there some unconverted loads?
@@ -292,7 +293,7 @@ static void ssa_rename_insn(struct basic_block *bb, struct instruction *insn)
if (!var || !var->torename)
break;
val = lookup_var(bb, var);
- convert_load_instruction(insn, val);
+ replace_with_pseudo(insn, val);
break;
case OP_PHI:
var = insn->type;
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-11-29 14:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-29 14:49 [PATCH 0/5] use replace_with_pseudo() for simplify_memops() Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 1/5] let replace_with_pseudo() use kill_instruction() Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 2/5] make a header for simplification Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 3/5] make replace_with_pseudo() extern Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 4/5] memops: move rewrite_load_instruction() here Luc Van Oostenryck
2020-11-29 14:49 ` [PATCH 5/5] replace convert_load_instruction() by replace_with_pseudo() 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).