diff mbox series

[3/4] slice: OP_SLICE needs the source's type: make it a kind of unop

Message ID 20210225233908.97275-4-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series small reorganization of OP_SLICE | expand

Commit Message

Luc Van Oostenryck Feb. 25, 2021, 11:39 p.m. UTC
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 <luc.vanoostenryck@gmail.com>
---
 linearize.c | 5 +++--
 linearize.h | 5 +----
 liveness.c  | 5 +----
 3 files changed, 5 insertions(+), 10 deletions(-)

Comments

Ramsay Jones Feb. 26, 2021, 11:56 p.m. UTC | #1
On 25/02/2021 23:39, Luc Van Oostenryck wrote:
> 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 <luc.vanoostenryck@gmail.com>
> ---
>  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 96a717bc2909..7ab69d3ac968 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 4d83675caaf1..429f4797e359 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 30a9a5b6b169..755509e59b52 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);

wouldn't USES(src) be more appropriate? They are not binops.

ATB,
Ramsay Jones

>  		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;
>
Luc Van Oostenryck Feb. 28, 2021, 9:40 p.m. UTC | #2
On Fri, Feb 26, 2021 at 11:56:58PM +0000, Ramsay Jones wrote:
> On 25/02/2021 23:39, Luc Van Oostenryck wrote:
> > diff --git a/liveness.c b/liveness.c
> > index 30a9a5b6b169..755509e59b52 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);
> 
> 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
diff mbox series

Patch

diff --git a/linearize.c b/linearize.c
index 96a717bc2909..7ab69d3ac968 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 4d83675caaf1..429f4797e359 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 30a9a5b6b169..755509e59b52 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;