diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-09-09 08:16:13 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-06-22 22:44:26 +0200 |
| commit | 8688eb7aaf138b3c613a97ee9eb1742b31cbe58f (patch) | |
| tree | d12e183e7e7651e18b09854fa868d7741c94e964 | |
| parent | 26e8c24c4f1cf6190dd79f8869fe7414bdc888db (diff) | |
| download | sparse-dev-8688eb7aaf138b3c613a97ee9eb1742b31cbe58f.tar.gz | |
new helper: replace_pseudo()
Replacing the value of an operand is a relatively common operation
during simplification. Since this operation currently needs two
more primitive operations which must have common arguments, it would
be better to have a helper for it.
Create the helper: replace_pseudo() and use it when possible.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 31 |
1 files changed, 19 insertions, 12 deletions
@@ -338,6 +338,20 @@ static inline int constant(pseudo_t pseudo) return pseudo->type == PSEUDO_VAL; } +/// +// replace one operand by a new value +// @insn: the instruction +// @pp: the address of the instruction's operand +// @new: the new value for the operand +// @return: REPEAT_CSE. +static inline int replace_pseudo(struct instruction *insn, pseudo_t *pp, pseudo_t new) +{ + pseudo_t old = *pp; + use_pseudo(insn, new, pp); + remove_usage(old, pp); + return REPEAT_CSE; +} + static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo) { convert_instruction_target(insn, pseudo); @@ -904,8 +918,7 @@ offset: warning(insn->pos, "crazy programmer"); } insn->offset += off->value; - use_pseudo(insn, new, &insn->src); - remove_usage(addr, &insn->src); + replace_pseudo(insn, &insn->src, new); return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP; } @@ -1077,8 +1090,7 @@ static int simplify_range(struct instruction *insn) */ static int simplify_cond_branch(struct instruction *br, pseudo_t cond, struct instruction *def, pseudo_t newcond) { - use_pseudo(br, newcond, &br->cond); - remove_usage(cond, &br->cond); + replace_pseudo(br, &br->cond, newcond); if (def->opcode == OP_SET_EQ) { struct basic_block *tmp = br->bb_true; br->bb_true = br->bb_false; @@ -1137,18 +1149,13 @@ static int simplify_branch(struct instruction *insn) insn->bb_true = insn->bb_false; insn->bb_false = tmp; } - use_pseudo(insn, def->src1, &insn->cond); - remove_usage(cond, &insn->cond); - return REPEAT_CSE; + return replace_pseudo(insn, &insn->cond, def->src1); } } if (def->opcode == OP_CAST || def->opcode == OP_SCAST) { int orig_size = def->orig_type ? def->orig_type->bit_size : 0; - if (def->size > orig_size) { - use_pseudo(insn, def->src, &insn->cond); - remove_usage(cond, &insn->cond); - return REPEAT_CSE; - } + if (def->size > orig_size) + return replace_pseudo(insn, &insn->cond, def->src); } } return 0; |
