aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-12-02 00:09:38 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-12-02 00:09:38 +0100
commita00755aafac28395aeb8fb3b6eb9f3801574cc97 (patch)
tree3c029f63095c7cb67e85d761ee658ef44fcca744
parent269d7b9ec7a7d7ba6dcb5f4ca29ef888ce79f06a (diff)
parent7624a18d61481b8411eff306a3dbf68209f0247b (diff)
downloadsparse-a00755aafac28395aeb8fb3b6eb9f3801574cc97.tar.gz
Merge branch 'kill-replace' into next
* let replace_with_pseudo() use kill_instruction() * move rewrite_load_instruction() to memops.c * replace convert_load_instruction() by replace_with_pseudo()
-rw-r--r--flow.c48
-rw-r--r--flow.h3
-rw-r--r--memops.c46
-rw-r--r--optimize.c1
-rw-r--r--simplify.c21
-rw-r--r--simplify.h10
-rw-r--r--ssa.c9
7 files changed, 64 insertions, 74 deletions
diff --git a/flow.c b/flow.c
index 9b43e01a..bda277aa 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);
@@ -518,47 +513,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 c3461c8c..46d76a78 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 *);
@@ -39,8 +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);
-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 6baf4d16..d96bd8a9 100644
--- a/memops.c
+++ b/memops.c
@@ -14,8 +14,50 @@
#include "parse.h"
#include "expression.h"
#include "linearize.h"
+#include "simplify.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.
+ */
+ replace_with_pseudo(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)
@@ -131,7 +173,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);
@@ -145,7 +187,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/optimize.c b/optimize.c
index 9b754831..3351e67b 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 334839a2..851f9420 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"
#include "flowgraph.h"
@@ -452,26 +453,10 @@ 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);
-
- 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)
diff --git a/simplify.h b/simplify.h
new file mode 100644
index 00000000..ed3dd971
--- /dev/null
+++ b/simplify.h
@@ -0,0 +1,10 @@
+#ifndef SIMPLIFY_H
+#define SIMPLIFY_H
+
+#include "linearize.h"
+
+int simplify_instruction(struct instruction *insn);
+
+int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo);
+
+#endif
diff --git a/ssa.c b/ssa.c
index 3e880050..a2e27030 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;