IR_KPTR holds a const pointer to possibly non-const content.
IR_KKPTR holds a const pointer to definitely const content.
Note that only content known by the VM to be const qualifies.
Content tagged as const by users (e.g. const char *) doesn't.
#endif
} else {
lua_assert(ir->o == IR_KINT || ir->o == IR_KGC ||
- ir->o == IR_KPTR || ir->o == IR_KNULL);
+ ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL);
emit_loadi(as, r, ir->i);
}
return r;
#endif
} else {
lua_assert(ir->o == IR_KINT || ir->o == IR_KGC ||
- ir->o == IR_KPTR || ir->o == IR_KNULL);
+ ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL);
emit_loadi(as, dest, ir->i);
return;
}
{
IRIns *ir = IR(ref);
as->mrm.idx = RID_NONE;
- if (ir->o == IR_KPTR) {
+ if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {
as->mrm.ofs = ir->i;
as->mrm.base = RID_NONE;
} else if (ir->o == IR_STRREF) {
}
/* Intern 32 bit pointer constant. */
-TRef lj_ir_kptr(jit_State *J, void *ptr)
+TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr)
{
IRIns *ir, *cir = J->cur.ir;
IRRef ref;
lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr);
- for (ref = J->chain[IR_KPTR]; ref; ref = cir[ref].prev)
+ for (ref = J->chain[op]; ref; ref = cir[ref].prev)
if (mref(cir[ref].ptr, void) == ptr)
goto found;
ref = ir_nextk(J);
ir = IR(ref);
setmref(ir->ptr, ptr);
ir->t.irt = IRT_P32;
- ir->o = IR_KPTR;
- ir->prev = J->chain[IR_KPTR];
- J->chain[IR_KPTR] = (IRRef1)ref;
+ ir->o = op;
+ ir->prev = J->chain[op];
+ J->chain[op] = (IRRef1)ref;
found:
return TREF(ref, IRT_P32);
}
case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break;
case IR_KINT: setintV(tv, ir->i); break;
case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break;
- case IR_KPTR: case IR_KNULL: setlightudV(tv, mref(ir->ptr, void)); break;
+ case IR_KPTR: case IR_KKPTR: case IR_KNULL:
+ setlightudV(tv, mref(ir->ptr, void));
+ break;
case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break;
#if LJ_HASFFI
case IR_KINT64: {
_(KINT, N , cst, ___) \
_(KGC, N , cst, ___) \
_(KPTR, N , cst, ___) \
+ _(KKPTR, N , cst, ___) \
_(KNULL, N , cst, ___) \
_(KNUM, N , cst, ___) \
_(KINT64, N , cst, ___) \
#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
#define ir_k64(ir) \
check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
-#define ir_kptr(ir) check_exp((ir)->o == IR_KPTR, mref((ir)->ptr, void))
+#define ir_kptr(ir) \
+ check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void))
LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W);
LJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n);
LJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64);
LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t);
-LJ_FUNC TRef lj_ir_kptr(jit_State *J, void *ptr);
+LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr);
LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t);
LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot);
#define lj_ir_kstr(J, str) lj_ir_kgc(J, obj2gco((str)), IRT_STR)
#define lj_ir_ktab(J, tab) lj_ir_kgc(J, obj2gco((tab)), IRT_TAB)
#define lj_ir_kfunc(J, func) lj_ir_kgc(J, obj2gco((func)), IRT_FUNC)
+#define lj_ir_kptr(J, ptr) lj_ir_kptr_(J, IR_KPTR, (ptr))
+#define lj_ir_kkptr(J, ptr) lj_ir_kptr_(J, IR_KKPTR, (ptr))
/* Special FP constants. */
#define lj_ir_knum_zero(J) lj_ir_knum_u64(J, U64x(00000000,00000000))
/* -- Constant folding for strings ---------------------------------------- */
-LJFOLD(SNEW KPTR KINT)
+LJFOLD(SNEW KKPTR KINT)
LJFOLDF(kfold_snew_kptr)
{
GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i);
{
GCstr *str = ir_kstr(fleft);
lua_assert((MSize)fright->i < str->len);
- return lj_ir_kptr(J, (char *)strdata(str) + fright->i);
+ return lj_ir_kkptr(J, (char *)strdata(str) + fright->i);
}
LJFOLD(STRREF SNEW any)
#else
ptrdiff_t ofs = fright->i;
#endif
- return lj_ir_kptr(J, (char *)o + ofs);
+ return lj_ir_kkptr(J, (char *)o + ofs);
}
LJFOLD(ADD KPTR KINT)
LJFOLD(ADD KPTR KINT64)
+LJFOLD(ADD KKPTR KINT)
+LJFOLD(ADD KKPTR KINT64)
LJFOLDF(kfold_add_kptr)
{
void *p = ir_kptr(fleft);
#else
ptrdiff_t ofs = fright->i;
#endif
- return lj_ir_kptr(J, (char *)p + ofs);
+ return lj_ir_kptr_(J, fleft->o, (char *)p + ofs);
}
/* -- Constant folding of conversions ------------------------------------- */
LJFOLDX(lj_opt_fwd_aload)
/* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */
-LJFOLD(HLOAD KPTR)
-LJFOLDF(kfold_hload_kptr)
+LJFOLD(HLOAD KKPTR)
+LJFOLDF(kfold_hload_kkptr)
{
UNUSED(J);
lua_assert(ir_kptr(fleft) == niltvg(J2G(J)));
LJFOLDF(fwd_href_tnew)
{
if (lj_opt_fwd_href_nokey(J))
- return lj_ir_kptr(J, niltvg(J2G(J)));
+ return lj_ir_kkptr(J, niltvg(J2G(J)));
return NEXTFOLD;
}
lj_ir_kvalue(J->L, &keyv, fright);
if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) &&
lj_opt_fwd_href_nokey(J))
- return lj_ir_kptr(J, niltvg(J2G(J)));
+ return lj_ir_kkptr(J, niltvg(J2G(J)));
return NEXTFOLD;
}
}
}
-LJFOLD(XLOAD KPTR any)
+/* Only fold for KKPTR. The pointer _and_ the contents must be const. */
+LJFOLD(XLOAD KKPTR any)
LJFOLDF(xload_kptr)
{
TRef tr = kfold_xload(J, fins, ir_kptr(fleft));
IRType t = itype2irt(oldv);
TRef res;
if (oldv == niltvg(J2G(J))) {
- emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kptr(J, niltvg(J2G(J))));
+ emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
res = TREF_NIL;
} else {
res = emitir(IRTG(loadop, t), xref, 0);
emitir(IRTG(loadop, IRT_NIL), xref, 0); /* Guard for nil value. */
else if (xrefop == IR_HREF)
emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32),
- xref, lj_ir_kptr(J, niltvg(J2G(J))));
+ xref, lj_ir_kkptr(J, niltvg(J2G(J))));
if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) {
lua_assert(hasmm);
goto handlemm;
} else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) {
/* Cannot derive that the previous value was non-nil, must do checks. */
if (xrefop == IR_HREF) /* Guard against store to niltv. */
- emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kptr(J, niltvg(J2G(J))));
+ emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
if (ix->idxchain) { /* Metamethod lookup required? */
/* A check for NULL metatable is cheaper (hoistable) than a load. */
if (!mt) {