aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/example.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-21 13:09:36 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-21 23:05:03 +0100
commit45e0e859a9cf2d14546dd5597a777926087928f0 (patch)
treeae6bd62a48241896b4708b704f37251973aecd50 /example.c
parent1221dc1c8c4299c57bb53a7b0b8a8e4e8729f9d6 (diff)
downloadsparse-dev-45e0e859a9cf2d14546dd5597a777926087928f0.tar.gz
add a new instruction for label-as-value
Convert OP_SETVAL of a label into a new instruction: OP_LABEL. There is 2 reasons to do this: *) there is slightly less checking to be done in later phases (since OP_SETVAL can be for labels but also strings) *) OP_SETVAL is CSEd but this is largely useless because this instruction is hashed on the expression's address and these are (most) often not shared. With a separate instruction for label expressions, their CSE is now OK because the hashing is done on the BB. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'example.c')
-rw-r--r--example.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/example.c b/example.c
index 8a2b1ab4..0c2ddf50 100644
--- a/example.c
+++ b/example.c
@@ -66,6 +66,7 @@ static const char *opcodes[] = {
/* Memory */
[OP_LOAD] = "load",
[OP_STORE] = "store",
+ [OP_LABEL] = "label",
[OP_SETVAL] = "set",
/* Other */
@@ -619,7 +620,7 @@ static struct hardreg *fill_reg(struct bb_state *state, struct hardreg *hardreg,
case PSEUDO_ARG:
case PSEUDO_REG:
def = pseudo->def;
- if (def && def->opcode == OP_SETVAL) {
+ if (def && (def->opcode == OP_SETVAL || def->opcode == OP_LABEL)) {
output_insn(state, "movl $<%s>,%s", show_pseudo(def->target), hardreg->name);
break;
}
@@ -1375,10 +1376,11 @@ static void generate_one_insn(struct instruction *insn, struct bb_state *state)
}
/*
- * OP_SETVAL likewise doesn't actually generate any
+ * OP_LABEL & OP_SETVAL likewise doesn't actually generate any
* code. On use, the "def" of the pseudo will be
* looked up.
*/
+ case OP_LABEL:
case OP_SETVAL:
break;
@@ -1531,7 +1533,7 @@ static void fill_output(struct bb_state *state, pseudo_t pseudo, struct storage
return;
case PSEUDO_REG:
def = pseudo->def;
- if (def && def->opcode == OP_SETVAL) {
+ if (def && (def->opcode == OP_SETVAL || def->opcode == OP_LABEL)) {
write_val_to_storage(state, pseudo, out);
return;
}