Add IR_FLOAD with REF_NIL for field loads from GG_State.

Contributed by Peter Cawley.
This commit is contained in:
Mike Pall 2016-05-21 00:30:36 +02:00
parent cfa188f134
commit 786dbb2ebd
8 changed files with 72 additions and 31 deletions

View File

@ -162,8 +162,8 @@ lj_opt_narrow.o: lj_opt_narrow.c lj_obj.h lua.h luaconf.h lj_def.h \
lj_opt_sink.o: lj_opt_sink.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ lj_opt_sink.o: lj_opt_sink.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
lj_ir.h lj_jit.h lj_iropt.h lj_target.h lj_target_*.h lj_ir.h lj_jit.h lj_iropt.h lj_target.h lj_target_*.h
lj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \ lj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \
lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h \ lj_arch.h lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_dispatch.h \
lj_jit.h lj_ircall.h lj_iropt.h lj_vm.h lj_bc.h lj_jit.h lj_ir.h lj_ircall.h lj_iropt.h lj_vm.h
lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_str.h lj_tab.h \ lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_buf.h lj_str.h lj_tab.h \
lj_func.h lj_state.h lj_bc.h lj_ctype.h lj_strfmt.h lj_lex.h lj_parse.h \ lj_func.h lj_state.h lj_bc.h lj_ctype.h lj_strfmt.h lj_lex.h lj_parse.h \

View File

@ -997,6 +997,9 @@ static ARMIns asm_fxstoreins(IRIns *ir)
static void asm_fload(ASMState *as, IRIns *ir) static void asm_fload(ASMState *as, IRIns *ir)
{ {
if (ir->op1 == REF_NIL) {
lua_assert(!ra_used(ir)); /* We can end up here if DCE is turned off. */
} else {
Reg dest = ra_dest(as, ir, RSET_GPR); Reg dest = ra_dest(as, ir, RSET_GPR);
Reg idx = ra_alloc1(as, ir->op1, RSET_GPR); Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
ARMIns ai = asm_fxloadins(ir); ARMIns ai = asm_fxloadins(ir);
@ -1013,6 +1016,7 @@ static void asm_fload(ASMState *as, IRIns *ir)
emit_lso(as, ai, dest, idx, ofs); emit_lso(as, ai, dest, idx, ofs);
else else
emit_lsox(as, ai, dest, idx, ofs); emit_lsox(as, ai, dest, idx, ofs);
}
} }
static void asm_fstore(ASMState *as, IRIns *ir) static void asm_fstore(ASMState *as, IRIns *ir)

View File

@ -896,9 +896,14 @@ static MIPSIns asm_fxstoreins(IRIns *ir)
static void asm_fload(ASMState *as, IRIns *ir) static void asm_fload(ASMState *as, IRIns *ir)
{ {
Reg dest = ra_dest(as, ir, RSET_GPR); Reg dest = ra_dest(as, ir, RSET_GPR);
Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
MIPSIns mi = asm_fxloadins(ir); MIPSIns mi = asm_fxloadins(ir);
Reg idx;
int32_t ofs; int32_t ofs;
if (ir->op1 == REF_NIL) {
idx = RID_JGL;
ofs = ir->op2 - 32768;
} else {
idx = ra_alloc1(as, ir->op1, RSET_GPR);
if (ir->op2 == IRFL_TAB_ARRAY) { if (ir->op2 == IRFL_TAB_ARRAY) {
ofs = asm_fuseabase(as, ir->op1); ofs = asm_fuseabase(as, ir->op1);
if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
@ -907,6 +912,7 @@ static void asm_fload(ASMState *as, IRIns *ir)
} }
} }
ofs = field_ofs[ir->op2]; ofs = field_ofs[ir->op2];
}
lua_assert(!irt_isfp(ir->t)); lua_assert(!irt_isfp(ir->t));
emit_tsi(as, mi, dest, idx, ofs); emit_tsi(as, mi, dest, idx, ofs);
} }

View File

@ -804,9 +804,14 @@ static PPCIns asm_fxstoreins(IRIns *ir)
static void asm_fload(ASMState *as, IRIns *ir) static void asm_fload(ASMState *as, IRIns *ir)
{ {
Reg dest = ra_dest(as, ir, RSET_GPR); Reg dest = ra_dest(as, ir, RSET_GPR);
Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
PPCIns pi = asm_fxloadins(ir); PPCIns pi = asm_fxloadins(ir);
Reg idx;
int32_t ofs; int32_t ofs;
if (ir->op1 == REF_NIL) {
idx = RID_JGL;
ofs = ir->op2 - 32768;
} else {
idx = ra_alloc1(as, ir->op1, RSET_GPR);
if (ir->op2 == IRFL_TAB_ARRAY) { if (ir->op2 == IRFL_TAB_ARRAY) {
ofs = asm_fuseabase(as, ir->op1); ofs = asm_fuseabase(as, ir->op1);
if (ofs) { /* Turn the t->array load into an add for colocated arrays. */ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
@ -815,6 +820,7 @@ static void asm_fload(ASMState *as, IRIns *ir)
} }
} }
ofs = field_ofs[ir->op2]; ofs = field_ofs[ir->op2];
}
lua_assert(!irt_isi8(ir->t)); lua_assert(!irt_isi8(ir->t));
emit_tai(as, pi, dest, idx, ofs); emit_tai(as, pi, dest, idx, ofs);
} }

View File

@ -205,8 +205,13 @@ static void asm_fuseahuref(ASMState *as, IRRef ref, RegSet allow)
static void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow) static void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow)
{ {
lua_assert(ir->o == IR_FLOAD || ir->o == IR_FREF); lua_assert(ir->o == IR_FLOAD || ir->o == IR_FREF);
as->mrm.ofs = field_ofs[ir->op2];
as->mrm.idx = RID_NONE; as->mrm.idx = RID_NONE;
if (ir->op1 == REF_NIL) {
as->mrm.ofs = (int32_t)ir->op2 + ptr2addr(J2GG(as->J));
as->mrm.base = RID_NONE;
return;
}
as->mrm.ofs = field_ofs[ir->op2];
if (irref_isk(ir->op1)) { if (irref_isk(ir->op1)) {
as->mrm.ofs += IR(ir->op1)->i; as->mrm.ofs += IR(ir->op1)->i;
as->mrm.base = RID_NONE; as->mrm.base = RID_NONE;
@ -369,6 +374,10 @@ static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow)
return RID_MRM; return RID_MRM;
} }
} }
if (ir->o == IR_FLOAD && ir->op1 == REF_NIL) {
asm_fusefref(as, ir, RSET_EMPTY);
return RID_MRM;
}
if (!(as->freeset & allow) && !irref_isk(ref) && if (!(as->freeset & allow) && !irref_isk(ref) &&
(allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref))) (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref)))
goto fusespill; goto fusespill;

View File

@ -145,6 +145,14 @@ TRef lj_ir_call(jit_State *J, IRCallID id, ...)
return emitir(CCI_OPTYPE(ci), tr, id); return emitir(CCI_OPTYPE(ci), tr, id);
} }
/* Load field of type t from GG_State + offset. */
LJ_FUNC TRef lj_ir_ggfload(jit_State *J, IRType t, uintptr_t ofs)
{
lua_assert(ofs >= IRFL__MAX && ofs < REF_BIAS);
lj_ir_set(J, IRT(IR_FLOAD, t), REF_NIL, ofs);
return lj_opt_fold(J);
}
/* -- Interning of constants ---------------------------------------------- */ /* -- Interning of constants ---------------------------------------------- */
/* /*

View File

@ -36,6 +36,8 @@ static LJ_AINLINE IRRef lj_ir_nextins(jit_State *J)
return ref; return ref;
} }
LJ_FUNC TRef lj_ir_ggfload(jit_State *J, IRType t, uintptr_t ofs);
/* Interning of constants. */ /* Interning of constants. */
LJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k); LJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k);
LJ_FUNC void lj_ir_k64_freeall(jit_State *J); LJ_FUNC void lj_ir_k64_freeall(jit_State *J);

View File

@ -12,6 +12,7 @@
#include "lj_err.h" #include "lj_err.h"
#include "lj_buf.h" #include "lj_buf.h"
#include "lj_dispatch.h"
#include "lj_ir.h" #include "lj_ir.h"
#include "lj_jit.h" #include "lj_jit.h"
#include "lj_ircall.h" #include "lj_ircall.h"
@ -448,6 +449,11 @@ static void split_ir(jit_State *J)
case IR_STRTO: case IR_STRTO:
hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref); hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);
break; break;
case IR_FLOAD:
lua_assert(ir->op1 == REF_NIL);
hi = lj_ir_kint(J, *(int32_t*)((char*)J2GG(J) + ir->op2 + LJ_LE*4));
nir->op2 += LJ_BE*4;
break;
case IR_XLOAD: { case IR_XLOAD: {
IRIns inslo = *nir; /* Save/undo the emit of the lo XLOAD. */ IRIns inslo = *nir; /* Save/undo the emit of the lo XLOAD. */
J->cur.nins--; J->cur.nins--;