diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-12-02 00:09:38 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-12-02 00:09:38 +0100 |
commit | a00755aafac28395aeb8fb3b6eb9f3801574cc97 (patch) | |
tree | 3c029f63095c7cb67e85d761ee658ef44fcca744 | |
parent | 269d7b9ec7a7d7ba6dcb5f4ca29ef888ce79f06a (diff) | |
parent | 7624a18d61481b8411eff306a3dbf68209f0247b (diff) | |
download | sparse-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.c | 48 | ||||
-rw-r--r-- | flow.h | 3 | ||||
-rw-r--r-- | memops.c | 46 | ||||
-rw-r--r-- | optimize.c | 1 | ||||
-rw-r--r-- | simplify.c | 21 | ||||
-rw-r--r-- | simplify.h | 10 | ||||
-rw-r--r-- | ssa.c | 9 |
7 files changed, 64 insertions, 74 deletions
@@ -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) @@ -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); @@ -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; } @@ -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" @@ -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 @@ -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; |