mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
FFI: Drop IR_CNEWI. Add IR_CNEWP only for pointers/refs.
This commit is contained in:
parent
c98132e182
commit
255c6e8c87
10
lib/dump.lua
10
lib/dump.lua
@ -418,16 +418,12 @@ local function dump_ir(tr, dumpsnap, dumpreg)
|
|||||||
band(ot, 64) == 0 and " " or "+",
|
band(ot, 64) == 0 and " " or "+",
|
||||||
irtype[t], op))
|
irtype[t], op))
|
||||||
local m1 = band(m, 3)
|
local m1 = band(m, 3)
|
||||||
local op4 = sub(op, 1, 4)
|
if sub(op, 1, 4) == "CALL" then
|
||||||
if op4 == "CALL" then
|
|
||||||
out:write(format("%-10s (", vmdef.ircall[op2]))
|
out:write(format("%-10s (", vmdef.ircall[op2]))
|
||||||
if op1 ~= -1 then dumpcallargs(tr, op1) end
|
if op1 ~= -1 then dumpcallargs(tr, op1) end
|
||||||
out:write(")")
|
out:write(")")
|
||||||
elseif op4 == "CNEW" then
|
elseif op == "CNEW " and op2 == -1 then
|
||||||
out:write(formatk(tr, op2))
|
out:write(formatk(tr, op1))
|
||||||
if op1 ~= -1 then
|
|
||||||
out:write(" ("); dumpcallargs(tr, op1); out:write(")")
|
|
||||||
end
|
|
||||||
elseif m1 ~= 3 then -- op1 != IRMnone
|
elseif m1 ~= 3 then -- op1 != IRMnone
|
||||||
if op1 < 0 then
|
if op1 < 0 then
|
||||||
out:write(formatk(tr, op1))
|
out:write(formatk(tr, op1))
|
||||||
|
90
src/lj_asm.c
90
src/lj_asm.c
@ -2283,55 +2283,12 @@ static void asm_tdup(ASMState *as, IRIns *ir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LJ_HASFFI
|
#if LJ_HASFFI
|
||||||
static RegSet asm_cnew_init(ASMState *as, IRRef ref, int32_t ofs, RegSet allow)
|
|
||||||
{
|
|
||||||
IRIns *ir = IR(ref);
|
|
||||||
if (irref_isk(ref)) {
|
|
||||||
#if LJ_64
|
|
||||||
if (ir->o == IR_KNUM || ir->o == IR_KINT64) {
|
|
||||||
uint64_t k = ir_k64(ir)->u64;
|
|
||||||
if (checki32((int64_t)k)) {
|
|
||||||
emit_i32(as, (int32_t)k);
|
|
||||||
emit_rmro(as, XO_MOVmi, REX_64, RID_RET, ofs);
|
|
||||||
} else {
|
|
||||||
emit_movtomro(as, RID_ECX|REX_64, RID_RET, ofs);
|
|
||||||
emit_loadu64(as, RID_ECX, k);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
emit_movmroi(as, RID_RET, ofs, ir->i);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (ir->o == IR_KNUM) {
|
|
||||||
emit_rmro(as, XO_MOVSDto, RID_XMM0, RID_RET, ofs);
|
|
||||||
emit_loadn(as, RID_XMM0, ir_k64(ir));
|
|
||||||
} else if (ir->o == IR_KINT64) {
|
|
||||||
uint64_t k = ir_k64(ir)->u64;
|
|
||||||
emit_movmroi(as, RID_RET, ofs, (int32_t)k);
|
|
||||||
emit_movmroi(as, RID_RET, ofs+4, (int32_t)(k >> 32));
|
|
||||||
} else {
|
|
||||||
emit_movmroi(as, RID_RET, ofs, ir->i);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
Reg r;
|
|
||||||
if (irt_isnum(ir->t)) {
|
|
||||||
r = ra_alloc1(as, ref, (RSET_FPR & allow));
|
|
||||||
emit_rmro(as, XO_MOVSDto, r, RID_RET, ofs);
|
|
||||||
} else {
|
|
||||||
r = ra_alloc1(as, ref, (RSET_GPR & allow));
|
|
||||||
emit_movtomro(as, REX_64IR(ir, r), RID_RET, ofs);
|
|
||||||
}
|
|
||||||
rset_clear(allow, r);
|
|
||||||
}
|
|
||||||
return allow;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void asm_cnew(ASMState *as, IRIns *ir)
|
static void asm_cnew(ASMState *as, IRIns *ir)
|
||||||
{
|
{
|
||||||
CTState *cts = ctype_ctsG(J2G(as->J));
|
CTState *cts = ctype_ctsG(J2G(as->J));
|
||||||
CTypeID typeid = (CTypeID)IR(ir->op2)->i;
|
CTypeID typeid = (CTypeID)IR(ir->op1)->i;
|
||||||
CTSize sz = (ir->o == IR_CNEWI || ir->op1 == REF_NIL) ?
|
CTSize sz = (ir->o == IR_CNEWP || ir->op2 == REF_NIL) ?
|
||||||
lj_ctype_size(cts, typeid) : (CTSize)IR(ir->op1)->i;
|
lj_ctype_size(cts, typeid) : (CTSize)IR(ir->op2)->i;
|
||||||
const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
|
const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
|
||||||
IRRef args[2];
|
IRRef args[2];
|
||||||
lua_assert(sz != CTSIZE_INVALID);
|
lua_assert(sz != CTSIZE_INVALID);
|
||||||
@ -2339,18 +2296,35 @@ static void asm_cnew(ASMState *as, IRIns *ir)
|
|||||||
args[0] = ASMREF_L; /* lua_State *L */
|
args[0] = ASMREF_L; /* lua_State *L */
|
||||||
args[1] = ASMREF_TMP1; /* MSize size */
|
args[1] = ASMREF_TMP1; /* MSize size */
|
||||||
as->gcsteps++;
|
as->gcsteps++;
|
||||||
asm_setupresult(as, ir, ci); /* GCobj * */
|
asm_setupresult(as, ir, ci); /* GCcdata * */
|
||||||
|
|
||||||
/* Initialize immutable cdata object. */
|
/* Initialize pointer cdata object. */
|
||||||
if (ir->o == IR_CNEWI) {
|
if (ir->o == IR_CNEWP) {
|
||||||
RegSet allow = ~RSET_SCRATCH;
|
if (irref_isk(ir->op2)) {
|
||||||
IRRef ref = ir->op1;
|
IRIns *irk = IR(ir->op2);
|
||||||
if (IR(ref)->o == IR_CARG) { /* 2nd initializer. */
|
#if LJ_64
|
||||||
IRIns *ira = IR(ref);
|
if (irk->o == IR_KINT64) {
|
||||||
allow = asm_cnew_init(as, ira->op2, sizeof(GCcdata) + (sz>>1), allow);
|
uint64_t k = ir_k64(irk)->u64;
|
||||||
ref = ira->op1;
|
lua_assert(sz == 8);
|
||||||
|
if (checki32((int64_t)k)) {
|
||||||
|
emit_i32(as, (int32_t)k);
|
||||||
|
emit_rmro(as, XO_MOVmi, REX_64, RID_RET, sizeof(GCcdata));
|
||||||
|
} else {
|
||||||
|
emit_movtomro(as, RID_ECX|REX_64, RID_RET, sizeof(GCcdata));
|
||||||
|
emit_loadu64(as, RID_ECX, k);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
lua_assert(sz == 4);
|
||||||
|
emit_movmroi(as, RID_RET, sizeof(GCcdata), irk->i);
|
||||||
|
#if LJ_64
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
Reg r = ra_alloc1(as, ir->op2, (RSET_GPR & ~RSET_SCRATCH));
|
||||||
|
emit_movtomro(as, r + ((LJ_64 && sz == 8) ? REX_64 : 0),
|
||||||
|
RID_RET, sizeof(GCcdata));
|
||||||
}
|
}
|
||||||
asm_cnew_init(as, ref, sizeof(GCcdata), allow); /* 1st initializer. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Combine initialization of marked, gct and typeid. */
|
/* Combine initialization of marked, gct and typeid. */
|
||||||
@ -3675,7 +3649,7 @@ static void asm_ir(ASMState *as, IRIns *ir)
|
|||||||
case IR_SNEW: asm_snew(as, ir); break;
|
case IR_SNEW: asm_snew(as, ir); break;
|
||||||
case IR_TNEW: asm_tnew(as, ir); break;
|
case IR_TNEW: asm_tnew(as, ir); break;
|
||||||
case IR_TDUP: asm_tdup(as, ir); break;
|
case IR_TDUP: asm_tdup(as, ir); break;
|
||||||
case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
|
case IR_CNEW: case IR_CNEWP: asm_cnew(as, ir); break;
|
||||||
|
|
||||||
/* Write barriers. */
|
/* Write barriers. */
|
||||||
case IR_TBAR: asm_tbar(as, ir); break;
|
case IR_TBAR: asm_tbar(as, ir); break;
|
||||||
@ -3793,7 +3767,7 @@ static void asm_setup_regsp(ASMState *as, GCtrace *T)
|
|||||||
if (as->evenspill < 3) /* lj_str_new and lj_tab_newkey need 3 args. */
|
if (as->evenspill < 3) /* lj_str_new and lj_tab_newkey need 3 args. */
|
||||||
as->evenspill = 3;
|
as->evenspill = 3;
|
||||||
#endif
|
#endif
|
||||||
case IR_TNEW: case IR_TDUP: case IR_CNEW: case IR_CNEWI: case IR_TOSTR:
|
case IR_TNEW: case IR_TDUP: case IR_CNEW: case IR_CNEWP: case IR_TOSTR:
|
||||||
ir->prev = REGSP_HINT(RID_RET);
|
ir->prev = REGSP_HINT(RID_RET);
|
||||||
if (inloop)
|
if (inloop)
|
||||||
as->modset = RSET_SCRATCH;
|
as->modset = RSET_SCRATCH;
|
||||||
|
@ -260,7 +260,7 @@ static TRef crec_tv_ct(jit_State *J, CType *s, CTypeID sid, TRef sp)
|
|||||||
ptrdiff_t esz = (ptrdiff_t)(s->size >> 1);
|
ptrdiff_t esz = (ptrdiff_t)(s->size >> 1);
|
||||||
TRef ptr, tr1, tr2, dp;
|
TRef ptr, tr1, tr2, dp;
|
||||||
if (t == IRT_CDATA) goto err_nyi; /* NYI: float IRType. */
|
if (t == IRT_CDATA) goto err_nyi; /* NYI: float IRType. */
|
||||||
dp = emitir(IRTG(IR_CNEW, IRT_CDATA), TREF_NIL, lj_ir_kint(J, sid));
|
dp = emitir(IRTG(IR_CNEW, IRT_CDATA), lj_ir_kint(J, sid), TREF_NIL);
|
||||||
tr1 = emitir(IRT(IR_XLOAD, t), sp, 0);
|
tr1 = emitir(IRT(IR_XLOAD, t), sp, 0);
|
||||||
ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, esz));
|
ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, esz));
|
||||||
tr2 = emitir(IRT(IR_XLOAD, t), ptr, 0);
|
tr2 = emitir(IRT(IR_XLOAD, t), ptr, 0);
|
||||||
@ -274,7 +274,7 @@ static TRef crec_tv_ct(jit_State *J, CType *s, CTypeID sid, TRef sp)
|
|||||||
err_nyi:
|
err_nyi:
|
||||||
lj_trace_err(J, LJ_TRERR_NYICONV);
|
lj_trace_err(J, LJ_TRERR_NYICONV);
|
||||||
}
|
}
|
||||||
return emitir(IRTG(IR_CNEWI, IRT_CDATA), sp, lj_ir_kint(J, sid));
|
return emitir(IRTG(IR_CNEWP, IRT_CDATA), lj_ir_kint(J, sid), sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- Convert TValue to C type (store) ------------------------------------ */
|
/* -- Convert TValue to C type (store) ------------------------------------ */
|
||||||
@ -300,7 +300,7 @@ static void crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, TValue *sval)
|
|||||||
s = ctype_raw(cts, sid);
|
s = ctype_raw(cts, sid);
|
||||||
if (ctype_isptr(s->info)) {
|
if (ctype_isptr(s->info)) {
|
||||||
IRType t = (LJ_64 && s->size == 8) ? IRT_P64 : IRT_P32;
|
IRType t = (LJ_64 && s->size == 8) ? IRT_P64 : IRT_P32;
|
||||||
sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INIT1);
|
sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_PTR);
|
||||||
if (ctype_isref(s->info))
|
if (ctype_isref(s->info))
|
||||||
s = ctype_rawchild(cts, s);
|
s = ctype_rawchild(cts, s);
|
||||||
else
|
else
|
||||||
@ -356,7 +356,7 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)
|
|||||||
if (ctype_isptr(ct->info)) {
|
if (ctype_isptr(ct->info)) {
|
||||||
IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;
|
IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;
|
||||||
if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);
|
if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);
|
||||||
ptr = emitir(IRT(IR_FLOAD, t), ptr, IRFL_CDATA_INIT1);
|
ptr = emitir(IRT(IR_FLOAD, t), ptr, IRFL_CDATA_PTR);
|
||||||
ofs = 0;
|
ofs = 0;
|
||||||
ptr = crec_reassoc_ofs(J, ptr, &ofs, 1);
|
ptr = crec_reassoc_ofs(J, ptr, &ofs, 1);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@
|
|||||||
_(TNEW, AW, lit, lit) \
|
_(TNEW, AW, lit, lit) \
|
||||||
_(TDUP, AW, ref, ___) \
|
_(TDUP, AW, ref, ___) \
|
||||||
_(CNEW, AW, ref, ref) \
|
_(CNEW, AW, ref, ref) \
|
||||||
_(CNEWI, NW, ref, ref) /* CSE is ok, not marked as A. */ \
|
_(CNEWP, NW, ref, ref) /* CSE is ok, not marked as A. */ \
|
||||||
\
|
\
|
||||||
/* Write barriers. */ \
|
/* Write barriers. */ \
|
||||||
_(TBAR, S , ref, ___) \
|
_(TBAR, S , ref, ___) \
|
||||||
@ -188,9 +188,7 @@ IRFPMDEF(FPMENUM)
|
|||||||
_(UDATA_UDTYPE, offsetof(GCudata, udtype)) \
|
_(UDATA_UDTYPE, offsetof(GCudata, udtype)) \
|
||||||
_(UDATA_FILE, sizeof(GCudata)) \
|
_(UDATA_FILE, sizeof(GCudata)) \
|
||||||
_(CDATA_TYPEID, offsetof(GCcdata, typeid)) \
|
_(CDATA_TYPEID, offsetof(GCcdata, typeid)) \
|
||||||
_(CDATA_INIT1, sizeof(GCcdata)) \
|
_(CDATA_PTR, sizeof(GCcdata))
|
||||||
_(CDATA_INIT2_4, sizeof(GCcdata)+4) \
|
|
||||||
_(CDATA_INIT2_8, sizeof(GCcdata)+8)
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
#define FLENUM(name, ofs) IRFL_##name,
|
#define FLENUM(name, ofs) IRFL_##name,
|
||||||
|
@ -153,7 +153,7 @@ typedef IRRef (LJ_FASTCALL *FoldFunc)(jit_State *J);
|
|||||||
#define gcstep_barrier(J, ref) \
|
#define gcstep_barrier(J, ref) \
|
||||||
((ref) < J->chain[IR_LOOP] && \
|
((ref) < J->chain[IR_LOOP] && \
|
||||||
(J->chain[IR_SNEW] || J->chain[IR_TNEW] || J->chain[IR_TDUP] || \
|
(J->chain[IR_SNEW] || J->chain[IR_TNEW] || J->chain[IR_TDUP] || \
|
||||||
J->chain[IR_CNEW] || J->chain[IR_CNEWI] || J->chain[IR_TOSTR]))
|
J->chain[IR_CNEW] || J->chain[IR_CNEWP] || J->chain[IR_TOSTR]))
|
||||||
|
|
||||||
/* -- Constant folding for FP numbers ------------------------------------- */
|
/* -- Constant folding for FP numbers ------------------------------------- */
|
||||||
|
|
||||||
@ -1587,35 +1587,26 @@ LJFOLDF(fload_str_len_snew)
|
|||||||
|
|
||||||
/* The C type ID of cdata objects is immutable. */
|
/* The C type ID of cdata objects is immutable. */
|
||||||
LJFOLD(FLOAD CNEW IRFL_CDATA_TYPEID)
|
LJFOLD(FLOAD CNEW IRFL_CDATA_TYPEID)
|
||||||
LJFOLD(FLOAD CNEWI IRFL_CDATA_TYPEID)
|
LJFOLD(FLOAD CNEWP IRFL_CDATA_TYPEID)
|
||||||
LJFOLDF(fload_cdata_typeid_cnewi)
|
LJFOLDF(fload_cdata_typeid_cnewi)
|
||||||
{
|
{
|
||||||
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))
|
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))
|
||||||
return fleft->op2; /* No PHI barrier needed. CNEW/CNEWI op2 is const. */
|
return fleft->op1; /* No PHI barrier needed. CNEW/CNEWP op1 is const. */
|
||||||
return NEXTFOLD;
|
return NEXTFOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fixed initializers in cdata objects are immutable. */
|
/* Pointer cdata objects are immutable. */
|
||||||
LJFOLD(FLOAD CNEWI IRFL_CDATA_INIT1)
|
LJFOLD(FLOAD CNEWP IRFL_CDATA_PTR)
|
||||||
LJFOLD(FLOAD CNEWI IRFL_CDATA_INIT2_4)
|
LJFOLDF(fload_cdata_ptr_cnewi)
|
||||||
LJFOLD(FLOAD CNEWI IRFL_CDATA_INIT2_8)
|
|
||||||
LJFOLDF(fload_cdata_init_cnew)
|
|
||||||
{
|
{
|
||||||
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
|
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))
|
||||||
IRIns *ir = fleft;
|
return fleft->op2; /* Fold even across PHI to avoid allocations. */
|
||||||
/* Fold even across PHI to avoid expensive allocations. */
|
|
||||||
lua_assert(ir->op1 != REF_NIL);
|
|
||||||
if (IR(ir->op1)->o == IR_CARG) ir = IR(ir->op1);
|
|
||||||
return fins->op2 == IRFL_CDATA_INIT1 ? ir->op1 : ir->op2;
|
|
||||||
}
|
|
||||||
return NEXTFOLD;
|
return NEXTFOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
LJFOLD(FLOAD any IRFL_STR_LEN)
|
LJFOLD(FLOAD any IRFL_STR_LEN)
|
||||||
LJFOLD(FLOAD any IRFL_CDATA_TYPEID)
|
LJFOLD(FLOAD any IRFL_CDATA_TYPEID)
|
||||||
LJFOLD(FLOAD any IRFL_CDATA_INIT1)
|
LJFOLD(FLOAD any IRFL_CDATA_PTR)
|
||||||
LJFOLD(FLOAD any IRFL_CDATA_INIT2_4)
|
|
||||||
LJFOLD(FLOAD any IRFL_CDATA_INIT2_8)
|
|
||||||
LJFOLD(VLOAD any any) /* Vararg loads have no corresponding stores. */
|
LJFOLD(VLOAD any any) /* Vararg loads have no corresponding stores. */
|
||||||
LJFOLDX(lj_opt_cse)
|
LJFOLDX(lj_opt_cse)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user