Update LuaJIT to the latest 2.1.0 source (1d8b747)

This commit is contained in:
Alex Szpakowski
2020-10-12 18:09:06 -03:00
parent ec1ceaf373
commit 72540d2d5a
214 changed files with 4738 additions and 3800 deletions
+77 -62
View File
@@ -3,7 +3,7 @@
** AA: Alias Analysis using high-level semantic disambiguation.
** FWD: Load Forwarding (L2L) + Store Forwarding (S2L).
** DSE: Dead-Store Elimination.
** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
** Copyright (C) 2005-2020 Mike Pall. See Copyright Notice in luajit.h
*/
#define lj_opt_mem_c
@@ -18,6 +18,7 @@
#include "lj_jit.h"
#include "lj_iropt.h"
#include "lj_ircall.h"
#include "lj_dispatch.h"
/* Some local macros to save typing. Undef'd at the end. */
#define IR(ref) (&J->cur.ir[(ref)])
@@ -56,8 +57,8 @@ static AliasRet aa_table(jit_State *J, IRRef ta, IRRef tb)
{
IRIns *taba = IR(ta), *tabb = IR(tb);
int newa, newb;
lua_assert(ta != tb);
lua_assert(irt_istab(taba->t) && irt_istab(tabb->t));
lj_assertJ(ta != tb, "bad usage");
lj_assertJ(irt_istab(taba->t) && irt_istab(tabb->t), "bad usage");
/* Disambiguate new allocations. */
newa = (taba->o == IR_TNEW || taba->o == IR_TDUP);
newb = (tabb->o == IR_TNEW || tabb->o == IR_TDUP);
@@ -99,7 +100,7 @@ static AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb)
/* Disambiguate array references based on index arithmetic. */
int32_t ofsa = 0, ofsb = 0;
IRRef basea = ka, baseb = kb;
lua_assert(refb->o == IR_AREF);
lj_assertJ(refb->o == IR_AREF, "expected AREF");
/* Gather base and offset from t[base] or t[base+-ofs]. */
if (keya->o == IR_ADD && irref_isk(keya->op2)) {
basea = keya->op1;
@@ -117,8 +118,9 @@ static AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb)
return ALIAS_NO; /* t[base+-o1] vs. t[base+-o2] and o1 != o2. */
} else {
/* Disambiguate hash references based on the type of their keys. */
lua_assert((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) &&
(refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF));
lj_assertJ((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) &&
(refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF),
"bad xREF IR op %d or %d", refa->o, refb->o);
if (!irt_sametype(keya->t, keyb->t))
return ALIAS_NO; /* Different key types. */
}
@@ -192,7 +194,8 @@ static TRef fwd_ahload(jit_State *J, IRRef xref)
if (key->o == IR_KSLOT) key = IR(key->op1);
lj_ir_kvalue(J->L, &keyv, key);
tv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv);
lua_assert(itype2irt(tv) == irt_type(fins->t));
lj_assertJ(itype2irt(tv) == irt_type(fins->t),
"mismatched type in constant table");
if (irt_isnum(fins->t))
return lj_ir_knum_u64(J, tv->u64);
else if (LJ_DUALNUM && irt_isint(fins->t))
@@ -363,14 +366,11 @@ TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)
IRIns *ir;
/* Check for any intervening guards (includes conflicting loads). */
for (ir = IR(J->cur.nins-1); ir > store; ir--)
if (irt_isguard(ir->t) || ir->o == IR_CALLL)
if (irt_isguard(ir->t) || ir->o == IR_ALEN)
goto doemit; /* No elimination possible. */
/* Remove redundant store from chain and replace with NOP. */
*refp = store->prev;
store->o = IR_NOP;
store->t.irt = IRT_NIL;
store->op1 = store->op2 = 0;
store->prev = 0;
lj_ir_nop(store);
/* Now emit the new store instead. */
}
goto doemit;
@@ -381,6 +381,67 @@ doemit:
return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
}
/* ALEN forwarding. */
TRef LJ_FASTCALL lj_opt_fwd_alen(jit_State *J)
{
IRRef tab = fins->op1; /* Table reference. */
IRRef lim = tab; /* Search limit. */
IRRef ref;
/* Search for conflicting HSTORE with numeric key. */
ref = J->chain[IR_HSTORE];
while (ref > lim) {
IRIns *store = IR(ref);
IRIns *href = IR(store->op1);
IRIns *key = IR(href->op2);
if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) {
lim = ref; /* Conflicting store found, limits search for ALEN. */
break;
}
ref = store->prev;
}
/* Try to find a matching ALEN. */
ref = J->chain[IR_ALEN];
while (ref > lim) {
/* CSE for ALEN only depends on the table, not the hint. */
if (IR(ref)->op1 == tab) {
IRRef sref;
/* Search for aliasing table.clear. */
if (!fwd_aa_tab_clear(J, ref, tab))
break;
/* Search for hint-forwarding or conflicting store. */
sref = J->chain[IR_ASTORE];
while (sref > ref) {
IRIns *store = IR(sref);
IRIns *aref = IR(store->op1);
IRIns *fref = IR(aref->op1);
if (tab == fref->op1) { /* ASTORE to the same table. */
/* Detect t[#t+1] = x idiom for push. */
IRIns *idx = IR(aref->op2);
if (!irt_isnil(store->t) &&
idx->o == IR_ADD && idx->op1 == ref &&
IR(idx->op2)->o == IR_KINT && IR(idx->op2)->i == 1) {
/* Note: this requires an extra PHI check in loop unroll. */
fins->op2 = aref->op2; /* Set ALEN hint. */
}
goto doemit; /* Conflicting store, possibly giving a hint. */
} else if (aa_table(J, tab, fref->op1) == ALIAS_NO) {
goto doemit; /* Conflicting store. */
}
sref = store->prev;
}
return ref; /* Plain ALEN forwarding. */
}
ref = IR(ref)->prev;
}
doemit:
return EMITFOLD;
}
/* -- ULOAD forwarding ---------------------------------------------------- */
/* The current alias analysis for upvalues is very simplistic. It only
@@ -430,7 +491,6 @@ TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J)
cselim:
/* Try to find a matching load. Below the conflicting store, if any. */
ref = J->chain[IR_ULOAD];
while (ref > lim) {
IRIns *ir = IR(ref);
@@ -471,10 +531,7 @@ TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J)
goto doemit; /* No elimination possible. */
/* Remove redundant store from chain and replace with NOP. */
*refp = store->prev;
store->o = IR_NOP;
store->t.irt = IRT_NIL;
store->op1 = store->op2 = 0;
store->prev = 0;
lj_ir_nop(store);
if (ref+1 < J->cur.nins &&
store[1].o == IR_OBAR && store[1].op1 == xref) {
IRRef1 *bp = &J->chain[IR_OBAR];
@@ -483,10 +540,7 @@ TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J)
bp = &obar->prev;
/* Remove OBAR, too. */
*bp = obar->prev;
obar->o = IR_NOP;
obar->t.irt = IRT_NIL;
obar->op1 = obar->op2 = 0;
obar->prev = 0;
lj_ir_nop(obar);
}
/* Now emit the new store instead. */
}
@@ -577,10 +631,7 @@ TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J)
goto doemit; /* No elimination possible. */
/* Remove redundant store from chain and replace with NOP. */
*refp = store->prev;
store->o = IR_NOP;
store->t.irt = IRT_NIL;
store->op1 = store->op2 = 0;
store->prev = 0;
lj_ir_nop(store);
/* Now emit the new store instead. */
}
goto doemit;
@@ -831,10 +882,7 @@ TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J)
goto doemit; /* No elimination possible. */
/* Remove redundant store from chain and replace with NOP. */
*refp = store->prev;
store->o = IR_NOP;
store->t.irt = IRT_NIL;
store->op1 = store->op2 = 0;
store->prev = 0;
lj_ir_nop(store);
/* Now emit the new store instead. */
}
goto doemit;
@@ -845,39 +893,6 @@ doemit:
return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
}
/* -- Forwarding of lj_tab_len -------------------------------------------- */
/* This is rather simplistic right now, but better than nothing. */
TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J)
{
IRRef tab = fins->op1; /* Table reference. */
IRRef lim = tab; /* Search limit. */
IRRef ref;
/* Any ASTORE is a conflict and limits the search. */
if (J->chain[IR_ASTORE] > lim) lim = J->chain[IR_ASTORE];
/* Search for conflicting HSTORE with numeric key. */
ref = J->chain[IR_HSTORE];
while (ref > lim) {
IRIns *store = IR(ref);
IRIns *href = IR(store->op1);
IRIns *key = IR(href->op2);
if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) {
lim = ref; /* Conflicting store found, limits search for TLEN. */
break;
}
ref = store->prev;
}
/* Search for aliasing table.clear. */
if (!fwd_aa_tab_clear(J, lim, tab))
return lj_ir_emit(J);
/* Try to find a matching load. Below the conflicting store, if any. */
return lj_opt_cselim(J, lim);
}
/* -- ASTORE/HSTORE previous type analysis -------------------------------- */
/* Check whether the previous value for a table store is non-nil.