aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2016-12-18 22:18:00 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-20 22:35:08 +0200
commitce5f04a050cbc8bd92f718765616199a7f8c958a (patch)
treec88734578207d737e5086bdcdb84c1bf59929f99
parent97e6515a7944b2ed9ec5be4614066632682559d7 (diff)
downloadsparse-dev-ce5f04a050cbc8bd92f718765616199a7f8c958a.tar.gz
unop: add helper replace_with_unop()
Some simplifications reduce to transforming a binop into an unop. Add an helper for making this change easier and more readable. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/simplify.c b/simplify.c
index 4c6569eb..3cac124f 100644
--- a/simplify.c
+++ b/simplify.c
@@ -470,6 +470,20 @@ static inline int replace_with_value(struct instruction *insn, long long val)
return replace_with_pseudo(insn, value_pseudo(val));
}
+///
+// replace a binop with an unop
+// @insn: the instruction to be replaced
+// @op: the instruction's new opcode
+// @src: the instruction's new operand
+// @return: REPEAT_CSE
+static inline int replace_with_unop(struct instruction *insn, int op, pseudo_t src)
+{
+ insn->opcode = op;
+ replace_pseudo(insn, &insn->src1, src);
+ remove_usage(insn->src2, &insn->src2);
+ return REPEAT_CSE;
+}
+
static inline int def_opcode(pseudo_t p)
{
if (p->type != PSEUDO_REG)