aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-26 23:20:47 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-27 17:27:07 +0100
commit9e6eaf742cb4a66da9f9a15195420e43633c8fe6 (patch)
treeda0118a20bf9c3e557cc6ae5d9816488975ec8d8
parentc60a5e93310bbba8bf15c2a717061f41481e22d8 (diff)
downloadsparse-9e6eaf742cb4a66da9f9a15195420e43633c8fe6.tar.gz
add helper replace_binop()
Add an helper to replace a binop OP(a, b) and taking care to drop the usage of the previous operands. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/simplify.c b/simplify.c
index 24b3dcb5..046bf02c 100644
--- a/simplify.c
+++ b/simplify.c
@@ -498,6 +498,23 @@ static inline int replace_binop_value(struct instruction *insn, int op, long lon
}
///
+// replace binop's opcode and values
+// @insn: the instruction to be replaced
+// @op: the instruction's new opcode
+// @return: REPEAT_CSE
+static inline int replace_binop(struct instruction *insn, int op, pseudo_t *pa, pseudo_t a, pseudo_t *pb, pseudo_t b)
+{
+ pseudo_t olda = *pa;
+ pseudo_t oldb = *pb;
+ insn->opcode = op;
+ use_pseudo(insn, a, pa);
+ use_pseudo(insn, b, pb);
+ remove_usage(olda, pa);
+ remove_usage(oldb, pb);
+ return REPEAT_CSE;
+}
+
+///
// replace the opcode of an instruction
// @return: REPEAT_CSE
static inline int replace_opcode(struct instruction *insn, int op)