mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
String buffers, part 3b: Change IR_BUFHDR op2 mode bits to mode.
Sponsored by fmad.io.
This commit is contained in:
parent
6df650fe3f
commit
3a0cf69730
22
src/lj_asm.c
22
src/lj_asm.c
@ -1149,24 +1149,30 @@ static void asm_tvptr(ASMState *as, Reg dest, IRRef ref, MSize mode);
|
|||||||
static void asm_bufhdr(ASMState *as, IRIns *ir)
|
static void asm_bufhdr(ASMState *as, IRIns *ir)
|
||||||
{
|
{
|
||||||
Reg sb = ra_dest(as, ir, RSET_GPR);
|
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. */
|
/* Rematerialize const buffer pointer instead of likely spill. */
|
||||||
IRIns *irp = IR(ir->op1);
|
IRIns *irp = IR(ir->op1);
|
||||||
if (!(ra_hasreg(irp->r) || irp == ir-1 ||
|
if (!(ra_hasreg(irp->r) || irp == ir-1 ||
|
||||||
(irp == ir-2 && !ra_used(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);
|
irp = IR(irp->op1);
|
||||||
if (irref_isk(irp->op1)) {
|
if (irref_isk(irp->op1)) {
|
||||||
ra_weak(as, ra_allocref(as, ir->op1, RSET_GPR));
|
ra_weak(as, ra_allocref(as, ir->op1, RSET_GPR));
|
||||||
ir = irp;
|
ir = irp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, sb));
|
}
|
||||||
IRIns irbp;
|
default: lj_assertA(0, "bad BUFHDR op2 %d", ir->op2); break;
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
#if LJ_TARGET_X86ORX64
|
#if LJ_TARGET_X86ORX64
|
||||||
ra_left(as, sb, ir->op1);
|
ra_left(as, sb, ir->op1);
|
||||||
|
@ -586,11 +586,11 @@ LJFOLDF(bufput_append)
|
|||||||
{
|
{
|
||||||
/* New buffer, no other buffer op inbetween and same buffer? */
|
/* New buffer, no other buffer op inbetween and same buffer? */
|
||||||
if ((J->flags & JIT_F_OPT_FWD) &&
|
if ((J->flags & JIT_F_OPT_FWD) &&
|
||||||
!(fleft->op2 & IRBUFHDR_APPEND) &&
|
fleft->op2 == IRBUFHDR_RESET &&
|
||||||
fleft->prev == fright->op2 &&
|
fleft->prev == fright->op2 &&
|
||||||
fleft->op1 == IR(fright->op2)->op1) {
|
fleft->op1 == IR(fright->op2)->op1) {
|
||||||
IRRef ref = fins->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;
|
IR(ref)->op1 = fright->op1;
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
@ -626,14 +626,14 @@ LJFOLDF(bufstr_kfold_cse)
|
|||||||
"bad buffer constructor IR op %d", fleft->o);
|
"bad buffer constructor IR op %d", fleft->o);
|
||||||
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
|
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
|
||||||
if (fleft->o == IR_BUFHDR) { /* No put operations? */
|
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);
|
return lj_ir_kstr(J, &J2G(J)->strempty);
|
||||||
fins->op1 = fleft->op1;
|
fins->op1 = fleft->op1;
|
||||||
fins->op2 = fleft->prev; /* Relies on checks in bufput_append. */
|
fins->op2 = fleft->prev; /* Relies on checks in bufput_append. */
|
||||||
return CSEFOLD;
|
return CSEFOLD;
|
||||||
} else if (fleft->o == IR_BUFPUT) {
|
} else if (fleft->o == IR_BUFPUT) {
|
||||||
IRIns *irb = IR(fleft->op1);
|
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. */
|
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 ||
|
lj_assertJ(ira->o == IR_BUFHDR || ira->o == IR_BUFPUT ||
|
||||||
ira->o == IR_CALLL || ira->o == IR_CARG,
|
ira->o == IR_CALLL || ira->o == IR_CARG,
|
||||||
"bad buffer constructor IR op %d", ira->o);
|
"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. */
|
return ref; /* CSE succeeded. */
|
||||||
if (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab)
|
if (ira->o == IR_CALLL && ira->op2 == IRCALL_lj_buf_puttab)
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user