Use dedicated type for snapshot map entry.

Preparatory work for compressed snapshots.
This commit is contained in:
Mike Pall 2010-01-25 19:51:52 +01:00
parent 055396a69d
commit 47f1bc80d8
8 changed files with 36 additions and 33 deletions

View File

@ -331,7 +331,7 @@ LJLIB_CF(jit_util_tracesnap)
SnapNo sn = (SnapNo)lj_lib_checkint(L, 2); SnapNo sn = (SnapNo)lj_lib_checkint(L, 2);
if (T && sn < T->nsnap) { if (T && sn < T->nsnap) {
SnapShot *snap = &T->snap[sn]; SnapShot *snap = &T->snap[sn];
IRRef2 *map = &T->snapmap[snap->mapofs]; SnapEntry *map = &T->snapmap[snap->mapofs];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
GCtab *t; GCtab *t;
lua_createtable(L, nslots ? (int)nslots : 1, 0); lua_createtable(L, nslots ? (int)nslots : 1, 0);

View File

@ -925,7 +925,7 @@ static int asm_snap_canremat(ASMState *as)
static void asm_snap_alloc(ASMState *as) static void asm_snap_alloc(ASMState *as)
{ {
SnapShot *snap = &as->T->snap[as->snapno]; SnapShot *snap = &as->T->snap[as->snapno];
IRRef2 *map = &as->T->snapmap[snap->mapofs]; SnapEntry *map = &as->T->snapmap[snap->mapofs];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
for (s = 0; s < nslots; s++) { for (s = 0; s < nslots; s++) {
IRRef ref = snap_ref(map[s]); IRRef ref = snap_ref(map[s]);
@ -959,7 +959,7 @@ static void asm_snap_alloc(ASMState *as)
static int asm_snap_checkrename(ASMState *as, IRRef ren) static int asm_snap_checkrename(ASMState *as, IRRef ren)
{ {
SnapShot *snap = &as->T->snap[as->snapno]; SnapShot *snap = &as->T->snap[as->snapno];
IRRef2 *map = &as->T->snapmap[snap->mapofs]; SnapEntry *map = &as->T->snapmap[snap->mapofs];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
for (s = 0; s < nslots; s++) { for (s = 0; s < nslots; s++) {
IRRef ref = snap_ref(map[s]); IRRef ref = snap_ref(map[s]);
@ -2463,7 +2463,7 @@ static void asm_gc_sync(ASMState *as, SnapShot *snap, Reg base)
** only. This avoids register allocation state unification. ** only. This avoids register allocation state unification.
*/ */
RegSet allow = rset_exclude(RSET_SCRATCH & RSET_GPR, base); RegSet allow = rset_exclude(RSET_SCRATCH & RSET_GPR, base);
IRRef2 *map = &as->T->snapmap[snap->mapofs]; SnapEntry *map = &as->T->snapmap[snap->mapofs];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
for (s = 0; s < nslots; s++) { for (s = 0; s < nslots; s++) {
IRRef ref = snap_ref(map[s]); IRRef ref = snap_ref(map[s]);
@ -2965,8 +2965,8 @@ static void asm_tail_sync(ASMState *as)
{ {
SnapShot *snap = &as->T->snap[as->T->nsnap-1]; /* Last snapshot. */ SnapShot *snap = &as->T->snap[as->T->nsnap-1]; /* Last snapshot. */
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
IRRef2 *map = &as->T->snapmap[snap->mapofs]; SnapEntry *map = &as->T->snapmap[snap->mapofs];
IRRef2 *flinks = map + nslots + snap->nframelinks; SnapEntry *flinks = map + nslots + snap->nframelinks;
BCReg newbase = 0; BCReg newbase = 0;
BCReg secondbase = ~(BCReg)0; BCReg secondbase = ~(BCReg)0;
BCReg topslot = 0; BCReg topslot = 0;

View File

@ -119,8 +119,10 @@ typedef struct SnapShot {
} SnapShot; } SnapShot;
#define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */ #define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */
#define snap_ref(sn) ((IRRef)(IRRef1)(sn))
#define snap_ridsp(sn) ((sn) >> 16) /* Snapshot entry. */
typedef uint32_t SnapEntry;
#define snap_ref(sn) ((sn) & 0xffff)
/* Snapshot and exit numbers. */ /* Snapshot and exit numbers. */
typedef uint32_t SnapNo; typedef uint32_t SnapNo;
@ -138,7 +140,7 @@ typedef struct Trace {
IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */ IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */
IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */ IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */
SnapShot *snap; /* Snapshot array. */ SnapShot *snap; /* Snapshot array. */
IRRef2 *snapmap; /* Snapshot map. */ SnapEntry *snapmap; /* Snapshot map. */
uint16_t nsnap; /* Number of snapshots. */ uint16_t nsnap; /* Number of snapshots. */
uint16_t nsnapmap; /* Number of snapshot map elements. */ uint16_t nsnapmap; /* Number of snapshot map elements. */
GCRef startpt; /* Starting prototype. */ GCRef startpt; /* Starting prototype. */
@ -223,7 +225,7 @@ typedef struct jit_State {
IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */ IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */
SnapShot *snapbuf; /* Temp. snapshot buffer. */ SnapShot *snapbuf; /* Temp. snapshot buffer. */
IRRef2 *snapmapbuf; /* Temp. snapshot map buffer. */ SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */
MSize sizesnap; /* Size of temp. snapshot buffer. */ MSize sizesnap; /* Size of temp. snapshot buffer. */
MSize sizesnapmap; /* Size of temp. snapshot map buffer. */ MSize sizesnapmap; /* Size of temp. snapshot map buffer. */

View File

@ -23,7 +23,7 @@ static void dce_marksnap(jit_State *J)
SnapNo i, nsnap = J->cur.nsnap; SnapNo i, nsnap = J->cur.nsnap;
for (i = 0; i < nsnap; i++) { for (i = 0; i < nsnap; i++) {
SnapShot *snap = &J->cur.snap[i]; SnapShot *snap = &J->cur.snap[i];
IRRef2 *map = &J->cur.snapmap[snap->mapofs]; SnapEntry *map = &J->cur.snapmap[snap->mapofs];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
for (s = 0; s < nslots; s++) { for (s = 0; s < nslots; s++) {
IRRef ref = snap_ref(map[s]); IRRef ref = snap_ref(map[s]);

View File

@ -170,7 +170,7 @@ static void loop_unroll(jit_State *J)
uint32_t nphi = 0; uint32_t nphi = 0;
IRRef1 *subst; IRRef1 *subst;
SnapShot *osnap, *snap; SnapShot *osnap, *snap;
IRRef2 *loopmap; SnapEntry *loopmap;
BCReg loopslots; BCReg loopslots;
MSize nsnap, nsnapmap; MSize nsnap, nsnapmap;
IRRef ins, invar, osnapref; IRRef ins, invar, osnapref;
@ -198,9 +198,9 @@ static void loop_unroll(jit_State *J)
} }
nsnapmap = J->cur.nsnapmap; /* Use temp. copy to avoid undo. */ nsnapmap = J->cur.nsnapmap; /* Use temp. copy to avoid undo. */
if (LJ_UNLIKELY(nsnapmap*2 > J->sizesnapmap)) { if (LJ_UNLIKELY(nsnapmap*2 > J->sizesnapmap)) {
J->snapmapbuf = (IRRef2 *)lj_mem_realloc(J->L, J->snapmapbuf, J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf,
J->sizesnapmap*sizeof(IRRef2), J->sizesnapmap*sizeof(SnapEntry),
2*J->sizesnapmap*sizeof(IRRef2)); 2*J->sizesnapmap*sizeof(SnapEntry));
J->cur.snapmap = J->snapmapbuf; J->cur.snapmap = J->snapmapbuf;
J->sizesnapmap *= 2; J->sizesnapmap *= 2;
} }
@ -223,7 +223,7 @@ static void loop_unroll(jit_State *J)
/* Copy-substitute snapshot. */ /* Copy-substitute snapshot. */
if (ins >= osnapref) { if (ins >= osnapref) {
IRRef2 *nmap, *omap = &J->cur.snapmap[osnap->mapofs]; SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs];
BCReg s, nslots; BCReg s, nslots;
uint32_t nmapofs, nframelinks; uint32_t nmapofs, nframelinks;
if (irt_isguard(J->guardemit)) { /* Guard inbetween? */ if (irt_isguard(J->guardemit)) { /* Guard inbetween? */

View File

@ -2158,7 +2158,7 @@ static const BCIns *rec_setup_root(jit_State *J)
static void rec_setup_side(jit_State *J, Trace *T) static void rec_setup_side(jit_State *J, Trace *T)
{ {
SnapShot *snap = &T->snap[J->exitno]; SnapShot *snap = &T->snap[J->exitno];
IRRef2 *map = &T->snapmap[snap->mapofs]; SnapEntry *map = &T->snapmap[snap->mapofs];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
BloomFilter seen = 0; BloomFilter seen = 0;
for (s = 0; s < nslots; s++) { for (s = 0; s < nslots; s++) {

View File

@ -32,7 +32,7 @@
*/ */
/* Add all modified slots to the snapshot. */ /* Add all modified slots to the snapshot. */
static void snapshot_slots(jit_State *J, IRRef2 *map, BCReg nslots) static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots)
{ {
BCReg s; BCReg s;
for (s = 0; s < nslots; s++) { for (s = 0; s < nslots; s++) {
@ -42,12 +42,13 @@ static void snapshot_slots(jit_State *J, IRRef2 *map, BCReg nslots)
if (ir->o == IR_SLOAD && ir->op1 == s && !(ir->op2 & IRSLOAD_INHERIT)) if (ir->o == IR_SLOAD && ir->op1 == s && !(ir->op2 & IRSLOAD_INHERIT))
ref = 0; ref = 0;
} }
map[s] = (IRRef2)ref; map[s] = (SnapEntry)ref;
} }
return nslots;
} }
/* Add frame links at the end of the snapshot. */ /* Add frame links at the end of the snapshot. */
static MSize snapshot_framelinks(jit_State *J, IRRef2 *map) static MSize snapshot_framelinks(jit_State *J, SnapEntry *map)
{ {
cTValue *frame = J->L->base - 1; cTValue *frame = J->L->base - 1;
cTValue *lim = J->L->base - J->baseslot; cTValue *lim = J->L->base - J->baseslot;
@ -76,7 +77,7 @@ static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap)
{ {
BCReg nslots = J->baseslot + J->maxslot; BCReg nslots = J->baseslot + J->maxslot;
MSize nsm, nframelinks; MSize nsm, nframelinks;
IRRef2 *p; SnapEntry *p;
/* Conservative estimate. Continuation frames need 2 slots. */ /* Conservative estimate. Continuation frames need 2 slots. */
nsm = nsnapmap + nslots + (uint32_t)J->framedepth*2+1; nsm = nsnapmap + nslots + (uint32_t)J->framedepth*2+1;
if (LJ_UNLIKELY(nsm > J->sizesnapmap)) { /* Need to grow snapshot map? */ if (LJ_UNLIKELY(nsm > J->sizesnapmap)) { /* Need to grow snapshot map? */
@ -84,13 +85,13 @@ static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap)
nsm = 2*J->sizesnapmap; nsm = 2*J->sizesnapmap;
else if (nsm < 64) else if (nsm < 64)
nsm = 64; nsm = 64;
J->snapmapbuf = (IRRef2 *)lj_mem_realloc(J->L, J->snapmapbuf, J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf,
J->sizesnapmap*sizeof(IRRef2), nsm*sizeof(IRRef2)); J->sizesnapmap*sizeof(SnapEntry), nsm*sizeof(SnapEntry));
J->cur.snapmap = J->snapmapbuf; J->cur.snapmap = J->snapmapbuf;
J->sizesnapmap = nsm; J->sizesnapmap = nsm;
} }
p = &J->cur.snapmap[nsnapmap]; p = &J->cur.snapmap[nsnapmap];
snapshot_slots(J, p, nslots); nslots = snapshot_slots(J, p, nslots);
nframelinks = snapshot_framelinks(J, p + nslots); nframelinks = snapshot_framelinks(J, p + nslots);
J->cur.nsnapmap = (uint16_t)(nsnapmap + nslots + nframelinks); J->cur.nsnapmap = (uint16_t)(nsnapmap + nslots + nframelinks);
snap->mapofs = (uint16_t)nsnapmap; snap->mapofs = (uint16_t)nsnapmap;
@ -130,8 +131,8 @@ void lj_snap_shrink(jit_State *J)
{ {
BCReg nslots = J->baseslot + J->maxslot; BCReg nslots = J->baseslot + J->maxslot;
SnapShot *snap = &J->cur.snap[J->cur.nsnap-1]; SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];
IRRef2 *oflinks = &J->cur.snapmap[snap->mapofs + snap->nslots]; SnapEntry *oflinks = &J->cur.snapmap[snap->mapofs + snap->nslots];
IRRef2 *nflinks = &J->cur.snapmap[snap->mapofs + nslots]; SnapEntry *nflinks = &J->cur.snapmap[snap->mapofs + nslots];
uint32_t s, nframelinks = snap->nframelinks; uint32_t s, nframelinks = snap->nframelinks;
lua_assert(nslots < snap->nslots); lua_assert(nslots < snap->nslots);
snap->nslots = (uint8_t)nslots; snap->nslots = (uint8_t)nslots;
@ -171,7 +172,7 @@ void lj_snap_regspmap(uint16_t *rsmap, Trace *T, SnapNo snapno)
{ {
SnapShot *snap = &T->snap[snapno]; SnapShot *snap = &T->snap[snapno];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
IRRef2 *map = &T->snapmap[snap->mapofs]; SnapEntry *map = &T->snapmap[snap->mapofs];
BloomFilter rfilt = snap_renamefilter(T, snapno); BloomFilter rfilt = snap_renamefilter(T, snapno);
for (s = 0; s < nslots; s++) { for (s = 0; s < nslots; s++) {
IRRef ref = snap_ref(map[s]); IRRef ref = snap_ref(map[s]);
@ -193,8 +194,8 @@ void lj_snap_restore(jit_State *J, void *exptr)
Trace *T = J->trace[J->parent]; Trace *T = J->trace[J->parent];
SnapShot *snap = &T->snap[snapno]; SnapShot *snap = &T->snap[snapno];
BCReg s, nslots = snap->nslots; BCReg s, nslots = snap->nslots;
IRRef2 *map = &T->snapmap[snap->mapofs]; SnapEntry *map = &T->snapmap[snap->mapofs];
IRRef2 *flinks = map + nslots + snap->nframelinks; SnapEntry *flinks = map + nslots + snap->nframelinks;
TValue *o, *newbase, *ntop; TValue *o, *newbase, *ntop;
BloomFilter rfilt = snap_renamefilter(T, snapno); BloomFilter rfilt = snap_renamefilter(T, snapno);
lua_State *L = J->L; lua_State *L = J->L;

View File

@ -88,7 +88,7 @@ static Trace *trace_save(jit_State *J, Trace *T)
size_t szins = (T->nins-T->nk)*sizeof(IRIns); size_t szins = (T->nins-T->nk)*sizeof(IRIns);
size_t sz = sztr + szins + size_t sz = sztr + szins +
T->nsnap*sizeof(SnapShot) + T->nsnap*sizeof(SnapShot) +
T->nsnapmap*sizeof(IRRef2); T->nsnapmap*sizeof(SnapEntry);
Trace *T2 = lj_mem_newt(J->L, (MSize)sz, Trace); Trace *T2 = lj_mem_newt(J->L, (MSize)sz, Trace);
char *p = (char *)T2 + sztr; char *p = (char *)T2 + sztr;
memcpy(T2, T, sizeof(Trace)); memcpy(T2, T, sizeof(Trace));
@ -96,7 +96,7 @@ static Trace *trace_save(jit_State *J, Trace *T)
memcpy(p, T->ir+T->nk, szins); memcpy(p, T->ir+T->nk, szins);
p += szins; p += szins;
TRACE_COPYELEM(snap, nsnap, SnapShot) TRACE_COPYELEM(snap, nsnap, SnapShot)
TRACE_COPYELEM(snapmap, nsnapmap, IRRef2) TRACE_COPYELEM(snapmap, nsnapmap, SnapEntry)
lj_gc_barriertrace(J2G(J), T); lj_gc_barriertrace(J2G(J), T);
return T2; return T2;
} }
@ -118,7 +118,7 @@ static void trace_free(jit_State *J, TraceNo traceno)
J->trace[traceno] = NULL; J->trace[traceno] = NULL;
lj_mem_free(J2G(J), T, lj_mem_free(J2G(J), T,
((sizeof(Trace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) + ((sizeof(Trace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +
T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(IRRef2)); T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry));
} }
} }
@ -284,7 +284,7 @@ void lj_trace_freestate(global_State *g)
#endif #endif
lj_mcode_free(J); lj_mcode_free(J);
lj_ir_knum_freeall(J); lj_ir_knum_freeall(J);
lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, IRRef2); lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, SnapEntry);
lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot); lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot);
lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns); lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns);
lj_mem_freevec(g, J->trace, J->sizetrace, Trace *); lj_mem_freevec(g, J->trace, J->sizetrace, Trace *);