String buffers, part 3b: Change IR_BUFHDR op2 mode bits to mode.

Sponsored by fmad.io.
This commit is contained in:
Mike Pall 2021-07-19 16:33:13 +02:00
parent 6df650fe3f
commit 3a0cf69730
2 changed files with 19 additions and 13 deletions

View File

@ -1149,24 +1149,30 @@ static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode);
static void asm_bufhdr(ASMState *as, IRIns *ir)
{
Reg sb = ra_dest(as, ir, RSET_GPR);
if ((ir->op2 & IRBUFHDR_APPEND)) {
switch (ir->op2) {
case IRBUFHDR_RESET: {
Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));
IRIns irbp;
irbp.ot = IRT(0, IRT_PTR); /* Buffer data pointer type. */
emit_storeofs(as, &irbp, tmp, sb, offsetof(SBuf, w));
emit_loadofs(as, &irbp, tmp, sb, offsetof(SBuf, b));
break;
}
case IRBUFHDR_APPEND: {
/* Rematerialize const buffer pointer instead of likely spill. */
IRIns *irp = IR(ir->op1);
if (!(ra_hasreg(irp->r) || irp == ir-1 ||
(irp == ir-2 && !ra_used(ir-1)))) {
while (!(irp->o == IR_BUFHDR && !(irp->op2 & IRBUFHDR_APPEND)))
while (!(irp->o == IR_BUFHDR && irp->op2 == IRBUFHDR_RESET))
irp = IR(irp->op1);
if (irref_isk(irp->op1)) {
ra_weak(as, ra_allocref(as, ir->op1, RSET_GPR));
ir = irp;
}
}
} else {
Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));
IRIns irbp;
irbp.ot = IRT(0, IRT_PTR); /* Buffer data pointer type. */
emit_storeofs(as, &irbp, tmp, sb, offsetof(SBuf, w));
emit_loadofs(as, &irbp, tmp, sb, offsetof(SBuf, b));
break;
}
default: lj_assertA(0, "bad BUFHDR op2 %d", ir->op2); break;
}
#if LJ_TARGET_X86ORX64
ra_left(as, sb, ir->op1);

View File

@ -586,11 +586,11 @@ LJFOLDF(bufput_append)
{
/* New buffer, no other buffer op inbetween and same buffer? */
if ((J->flags & JIT_F_OPT_FWD) &&
!(fleft->op2 & IRBUFHDR_APPEND) &&
fleft->op2 == IRBUFHDR_RESET &&
fleft->prev == fright->op2 &&
fleft->op1 == IR(fright->op2)->op1) {
IRRef ref = fins->op1;
IR(ref)->op2 = (fleft->op2 | IRBUFHDR_APPEND); /* Modify BUFHDR. */
IR(ref)->op2 = IRBUFHDR_APPEND; /* Modify BUFHDR. */
IR(ref)->op1 = fright->op1;
return ref;
}
@ -626,14 +626,14 @@ LJFOLDF(bufstr_kfold_cse)
"bad buffer constructor IR op %d", fleft->o);
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
if (fleft->o == IR_BUFHDR) { /* No put operations? */
if (!(fleft->op2 & IRBUFHDR_APPEND)) /* Empty buffer? */
if (fleft->op2 == IRBUFHDR_RESET) /* Empty buffer? */
return lj_ir_kstr(J, &J2G(J)->strempty);
fins->op1 = fleft->op1;
fins->op2 = fleft->prev; /* Relies on checks in bufput_append. */
return CSEFOLD;
} else if (fleft->o == IR_BUFPUT) {
IRIns *irb = IR(fleft->op1);
if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND))
if (irb->o == IR_BUFHDR && irb->op2 == IRBUFHDR_RESET)
return fleft->op2; /* Shortcut for a single put operation. */
}
}
@ -646,7 +646,7 @@ LJFOLDF(bufstr_kfold_cse)
lj_assertJ(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT ||
ira->o == IR_CALLL || ira->o == IR_CARG,
"bad buffer constructor IR op %d", ira->o);
if (ira->o == IR_BUFHDR && !(ira->op2 & IRBUFHDR_APPEND))
if (ira->o == IR_BUFHDR && ira->op2 == IRBUFHDR_RESET)
return ref; /* CSE succeeded. */
if (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab)
break;