From c2d25e6aad7dd78fb2e1a4f2afd38a42f3ffa614 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 21 Feb 2021 23:54:42 +0100 Subject: slice: remove unneeded len from OP_SLICE OP_SLICE::len is necessarily equal to the result size. So remove this redundancy. Signed-off-by: Luc Van Oostenryck --- Documentation/IR.rst | 2 +- linearize.c | 3 +-- linearize.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Documentation/IR.rst b/Documentation/IR.rst index 38df84ff..e1613402 100644 --- a/Documentation/IR.rst +++ b/Documentation/IR.rst @@ -408,7 +408,7 @@ Others Extract a "slice" from an aggregate. * .base: (pseudo_t) aggregate (alias .src) - * .from, .len: offet & size of the "slice" within the aggregate + * .from: offset of the "slice" within the aggregate * .target: result * .type: type of .target diff --git a/linearize.c b/linearize.c index 0c9b0e59..96a717bc 100644 --- a/linearize.c +++ b/linearize.c @@ -470,7 +470,7 @@ const char *show_instruction(struct instruction *insn) break; case OP_SLICE: - buf += sprintf(buf, "%s <- %s, %d, %d", show_pseudo(insn->target), show_pseudo(insn->base), insn->from, insn->len); + buf += sprintf(buf, "%s <- %s, %d", show_pseudo(insn->target), show_pseudo(insn->base), insn->from); break; case OP_NOT: case OP_NEG: @@ -1239,7 +1239,6 @@ static pseudo_t linearize_slice(struct entrypoint *ep, struct expression *expr) insn->target = new; insn->from = expr->r_bitpos; - insn->len = expr->r_nrbits; use_pseudo(insn, pre, &insn->base); add_one_insn(ep, insn); return new; diff --git a/linearize.h b/linearize.h index cf0cf066..4d83675c 100644 --- a/linearize.h +++ b/linearize.h @@ -129,7 +129,7 @@ struct instruction { }; struct /* slice */ { pseudo_t base; - unsigned from, len; + unsigned from; }; struct /* setval */ { struct expression *val; -- cgit 1.2.3-korg From fc5213b3f0040d21d0579b20cea9c4212e7cb504 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 21 Feb 2021 23:54:42 +0100 Subject: slice: remove unneeded nr_nrbits from EXPR_SLICE EXPR_SLICE::r_nrbits is necessarily equal to its type's bit size. So remove this redundancy. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 1 - expression.h | 2 +- show-parse.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/evaluate.c b/evaluate.c index 41871e18..e13edf54 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2170,7 +2170,6 @@ static struct symbol *evaluate_member_dereference(struct expression *expr) } expr->r_bitpos += bytes_to_bits(offset); expr->type = EXPR_SLICE; - expr->r_nrbits = member->bit_size; expr->r_bitpos += member->bit_offset; expr->ctype = member; return member; diff --git a/expression.h b/expression.h index 3e9e9d85..f733c076 100644 --- a/expression.h +++ b/expression.h @@ -206,7 +206,7 @@ struct expression { // EXPR_SLICE struct /* slice */ { struct expression *base; - unsigned r_bitpos, r_nrbits; + unsigned r_bitpos; }; // EXPR_CAST, EXPR_FORCE_CAST, EXPR_IMPLIED_CAST, // EXPR_SIZEOF, EXPR_ALIGNOF and EXPR_PTRSIZEOF diff --git a/show-parse.c b/show-parse.c index 3ab8ec8f..e2fc18bb 100644 --- a/show-parse.c +++ b/show-parse.c @@ -819,7 +819,7 @@ static int show_slice(struct expression *expr) { int target = show_expression(expr->base); int new = new_pseudo(); - printf("\tslice.%d\t\tv%d,v%d,%d\n", expr->r_nrbits, target, new, expr->r_bitpos); + printf("\tslice.%d\t\tv%d,v%d,%d\n", expr->ctype->bit_size, target, new, expr->r_bitpos); return new; } -- cgit 1.2.3-korg From 04c02822a0750e3eb8ef2487e2407b3aa0b66245 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 26 Feb 2021 00:04:27 +0100 Subject: slice: OP_SLICE needs the source's type: make it a kind of unop OP_SLICE's source's type is needed for some simplifications. For example, in some cases it can be simplified into OP_TRUNC. So, merge its representation with the one for unops which also need the source's type. Signed-off-by: Luc Van Oostenryck --- linearize.c | 5 +++-- linearize.h | 5 +---- liveness.c | 5 +---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/linearize.c b/linearize.c index 96a717bc..7ab69d3a 100644 --- a/linearize.c +++ b/linearize.c @@ -470,7 +470,7 @@ const char *show_instruction(struct instruction *insn) break; case OP_SLICE: - buf += sprintf(buf, "%s <- %s, %d", show_pseudo(insn->target), show_pseudo(insn->base), insn->from); + buf += sprintf(buf, "%s <- %s, %d", show_pseudo(insn->target), show_pseudo(insn->src), insn->from); break; case OP_NOT: case OP_NEG: @@ -1239,7 +1239,8 @@ static pseudo_t linearize_slice(struct entrypoint *ep, struct expression *expr) insn->target = new; insn->from = expr->r_bitpos; - use_pseudo(insn, pre, &insn->base); + insn->orig_type = expr->base->ctype; + use_pseudo(insn, pre, &insn->src); add_one_insn(ep, insn); return new; } diff --git a/linearize.h b/linearize.h index 4d83675c..429f4797 100644 --- a/linearize.h +++ b/linearize.h @@ -113,6 +113,7 @@ struct instruction { }; struct /* unops */ { pseudo_t src; + unsigned from; /* slice */ struct symbol *orig_type; /* casts */ }; struct /* memops */ { @@ -127,10 +128,6 @@ struct instruction { pseudo_t _src1, _src2; // alias .src[12] struct symbol *itype; // input operands' type }; - struct /* slice */ { - pseudo_t base; - unsigned from; - }; struct /* setval */ { struct expression *val; }; diff --git a/liveness.c b/liveness.c index 30a9a5b6..755509e5 100644 --- a/liveness.c +++ b/liveness.c @@ -76,6 +76,7 @@ static void track_instruction_usage(struct basic_block *bb, struct instruction * /* Uni */ case OP_UNOP ... OP_UNOP_END: case OP_SYMADDR: + case OP_SLICE: USES(src1); DEFINES(target); break; @@ -121,10 +122,6 @@ static void track_instruction_usage(struct basic_block *bb, struct instruction * } END_FOR_EACH_PTR(pseudo); break; - case OP_SLICE: - USES(base); DEFINES(target); - break; - case OP_ASM: asm_liveness(bb, insn, def, use); break; -- cgit 1.2.3-korg From b2cbc0ff13976e13d5ad62779440526bc5fa5616 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 26 Feb 2021 00:19:52 +0100 Subject: slice: display the source's size, like for unops When displaying an OP_SLICE, the width is shown but the size of the source pseudo is useful too. So, display this size in a similar manner to the unops. Signed-off-by: Luc Van Oostenryck --- linearize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linearize.c b/linearize.c index 7ab69d3a..b06c0625 100644 --- a/linearize.c +++ b/linearize.c @@ -470,7 +470,7 @@ const char *show_instruction(struct instruction *insn) break; case OP_SLICE: - buf += sprintf(buf, "%s <- %s, %d", show_pseudo(insn->target), show_pseudo(insn->src), insn->from); + buf += sprintf(buf, "%s <- (%d) %s, %d", show_pseudo(insn->target), type_size(insn->orig_type), show_pseudo(insn->src), insn->from); break; case OP_NOT: case OP_NEG: -- cgit 1.2.3-korg From 778de2bf52a2bed588d1653aaebe2cbd25f80eac Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Feb 2021 22:43:24 +0100 Subject: liveness: use 'src' for unops instead of 'src1' --- liveness.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liveness.c b/liveness.c index 755509e5..5b10e5e1 100644 --- a/liveness.c +++ b/liveness.c @@ -77,7 +77,7 @@ static void track_instruction_usage(struct basic_block *bb, struct instruction * case OP_UNOP ... OP_UNOP_END: case OP_SYMADDR: case OP_SLICE: - USES(src1); DEFINES(target); + USES(src); DEFINES(target); break; case OP_SEL: -- cgit 1.2.3-korg