aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-26 00:19:15 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-27 17:27:06 +0100
commitc60a5e93310bbba8bf15c2a717061f41481e22d8 (patch)
tree268088ed626b97f0eacc5ec01113fcf10abfbded
parent449ab6d6e5db1cdae9e4e6becc1fa7e970694df5 (diff)
downloadsparse-c60a5e93310bbba8bf15c2a717061f41481e22d8.tar.gz
add helper make_insn_pair() & swap_insn()
Add two helpers to create instruction pair OUT(IN(a, b), c). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/simplify.c b/simplify.c
index d16390ca..24b3dcb5 100644
--- a/simplify.c
+++ b/simplify.c
@@ -506,6 +506,37 @@ static inline int replace_opcode(struct instruction *insn, int op)
return REPEAT_CSE;
}
+///
+// create an instruction pair OUT(IN(a, b), c)
+static int replace_insn_pair(struct instruction *out, int op_out, struct instruction *in, int op_in, pseudo_t a, pseudo_t b, pseudo_t c)
+{
+ pseudo_t old_a = in->src1;
+ pseudo_t old_b = in->src2;
+ pseudo_t old_1 = out->src1;
+ pseudo_t old_2 = out->src2;
+
+ use_pseudo(in, a, &in->src1);
+ use_pseudo(in, b, &in->src2);
+ use_pseudo(out, in->target, &out->src1);
+ use_pseudo(out, c, &out->src2);
+
+ remove_usage(old_a, &in->src1);
+ remove_usage(old_b, &in->src2);
+ remove_usage(old_1, &out->src1);
+ remove_usage(old_2, &out->src2);
+
+ out->opcode = op_out;
+ in->opcode = op_in;
+ return REPEAT_CSE;
+}
+
+///
+// create an instruction pair OUT(IN(a, b), c) with swapped opcodes
+static inline int swap_insn(struct instruction *out, struct instruction *in, pseudo_t a, pseudo_t b, pseudo_t c)
+{
+ return replace_insn_pair(out, in->opcode, in, out->opcode, a, b, c);
+}
+
static inline int def_opcode(pseudo_t p)
{
if (p->type != PSEUDO_REG)