[PATCH 2/3] new helper: replace_pseudo()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 simplify.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/simplify.c b/simplify.c
index 77d818e1f..5c3a744f0 100644
--- a/simplify.c
+++ b/simplify.c
@@ -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;
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux