small reorganization of OP_SLICE
Subsystems (2)
cover small reorganization of OP_SLICE
Slightly reorganize OP_SLICE instructions in preparation for some incoming changes involving them.
Luc Van Oostenryck (4):
slice: remove unneeded len from OP_SLICE
slice: remove unneeded nr_nrbits from EXPR_SLICE
slice: OP_SLICE needs the source's type: make it a kind of unop
slice: display the source's size, like for unops
Documentation/IR.rst | 2 +- evaluate.c | 1 - expression.h | 2 +- linearize.c | 6 +++--- linearize.h | 5 +---- liveness.c | 5 +---- show-parse.c | 2 +- 7 files changed, 8 insertions(+), 15 deletions(-)
Signature · 1 line
2.30.0
PATCH 1/4 slice: remove unneeded len from OP_SLICE
OP_SLICE::len is necessarily equal to the result size. So remove this redundancy.
--- Documentation/IR.rst | 2 +- linearize.c | 3 +-- linearize.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)
Documentation/IR.rst +1 -1
@@ -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: offet of the "slice" within the aggregate * .target: result * .type: type of .target
linearize.c +1 -2
@@ -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;
linearize.h +1 -1
@@ -129,7 +129,7 @@ struct instruction { };struct /* slice */ {pseudo_t base; -unsigned from, len; +unsigned from; };struct /* setval */ {struct expression *val;
Signature · 1 line
2.30.0
Re: [PATCH 1/4] slice: remove unneeded len from OP_SLICE
Quoted 15 lines · Luc Van Oostenryck
OP_SLICE::lenis necessarily equal to the result size. So remove this redundancy.Signed-off-by Luc Van Oostenryck <[email protected]>--- Documentation/IR.rst | 2 +- linearize.c | 3 +-- linearize.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)Documentation/IR.rst +0
-0
Documentation/IR.rst Others · line 411
Quoted 5 lines
Documentation/IR.rst +1
-1@@ -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: offet of the "slice" within the aggregate
s/offet/offset/
ATB,
Ramsay Jones
Quoted 38 lines
Documentation/IR.rst +0
-0* .target: result * .type: type of .targetlinearize.c +1
-2@@ -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;linearize.h +1
-1@@ -129,7 +129,7 @@ struct instruction { };struct /* slice */ {pseudo_t base; -unsigned from, len; +unsigned from; };struct /* setval */ {struct expression *val;
PATCH 2/4 slice: remove unneeded nr_nrbits from EXPR_SLICE
In reply to Luc Van OostenryckEXPR_SLICE::r_nrbits is necessarily equal to its type's bit size. So remove this redundancy.
--- evaluate.c | 1 - expression.h | 2 +- show-parse.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-)
evaluate.c +0 -1
@@ -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;
expression.h +1 -1
@@ -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
show-parse.c +1 -1
@@ -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; }
Signature · 1 line
2.30.0
PATCH 3/4 slice: OP_SLICE needs the source's type: make it a kind of unop
In reply to Luc Van OostenryckOP_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.
--- linearize.c | 5 +++-- linearize.h | 5 +---- liveness.c | 5 +---- 3 files changed, 5 insertions(+), 10 deletions(-)
linearize.c +3 -2
@@ -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; }
linearize.h +1 -4
@@ -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; };
liveness.c +1 -4
@@ -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 ;
Signature · 1 line
2.30.0
Re: [PATCH 3/4] slice: OP_SLICE needs the source's type: make it a kind of unop
Quoted 64 lines · Luc Van Oostenryck
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 <[email protected]>--- linearize.c | 5 +++-- linearize.h | 5 +---- liveness.c | 5 +---- 3 files changed, 5 insertions(+), 10 deletions(-)linearize.c +3
-2@@ -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; }linearize.h +1
-4@@ -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; };liveness.c +0
-0
liveness.c static void track_instruction_usage(struct basic_block *bb, struct instruction * · line 80
Quoted 5 lines
liveness.c +1
-0@@ -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);
wouldn't USES(src) be more appropriate? They are not binops.
ATB,
Ramsay Jones
Quoted 14 lines
liveness.c +0
-4break ;@@ -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 ;
Re: [PATCH 3/4] slice: OP_SLICE needs the source's type: make it a kind of unop
Quoted 13 lines · Ramsay Jones
liveness.c static void track_instruction_usage(struct basic_block *bb, struct instruction * · line 80
Quoted 10 lines · Luc Van Oostenryck
liveness.c +1
-0@@ -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);wouldn't USES(src) be more appropriate? They are not binops.
Yes, even though they are synonymous (and documented as such) it makes thinks slightly clearer. I'll change this in a separate patch.
Thank you (also for the 2 other patches),
-- Luc
PATCH 4/4 slice: display the source's size, like for unops
In reply to Luc Van OostenryckWhen displaying an OP_SLICE, the width is shown but the size of the source pseudo is useful to. So display the it, like done for unops.
--- linearize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linearize.c +1 -1
@@ -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 :
Signature · 1 line
2.30.0
Re: [PATCH 4/4] slice: display the source's size, like for unops
Quoted 3 lines · Luc Van Oostenryck
When displaying an
OP_SLICE, the width is shown but the size of the source pseudo is useful to. So display the it, like done for unops.
Hmm, s/useful to./useful too./, s/the it,/it/,
s/like.*unops./in a similar manner to the unops./
... if that makes sense! ;-)
ie:
When displaying an OP_SLICE, the width is shown but the size of the source pseudo is useful too. So, display it in a similar manner to the unops.
ATB,
Ramsay Jones
Quoted 20 lines
Signed-off-by Luc Van Oostenryck <[email protected]>--- linearize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)linearize.c +1
-1@@ -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 :