Use weak guards for on-trace allocations.

This commit is contained in:
Mike Pall 2021-03-23 00:33:34 +01:00
parent de89c602c2
commit ddd0fd8f37
4 changed files with 51 additions and 49 deletions

View File

@ -707,7 +707,7 @@ static void LJ_FASTCALL recff_bit_tohex(jit_State *J, RecordFFData *rd)
#if LJ_HASFFI #if LJ_HASFFI
TRef hdr = recff_bufhdr(J); TRef hdr = recff_bufhdr(J);
TRef tr = recff_bit64_tohex(J, rd, hdr); TRef tr = recff_bit64_tohex(J, rd, hdr);
J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);
#else #else
recff_nyiu(J, rd); /* Don't bother working around this NYI. */ recff_nyiu(J, rd); /* Don't bother working around this NYI. */
#endif #endif
@ -833,8 +833,8 @@ static void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd)
if (i > 1) { /* Concatenate the strings, if there's more than one. */ if (i > 1) { /* Concatenate the strings, if there's more than one. */
TRef hdr = recff_bufhdr(J), tr = hdr; TRef hdr = recff_bufhdr(J), tr = hdr;
for (i = 0; J->base[i] != 0; i++) for (i = 0; J->base[i] != 0; i++)
tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, J->base[i]); tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, J->base[i]);
J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);
} else if (i == 0) { } else if (i == 0) {
J->base[0] = lj_ir_kstr(J, &J2G(J)->strempty); J->base[0] = lj_ir_kstr(J, &J2G(J)->strempty);
} }
@ -852,19 +852,19 @@ static void LJ_FASTCALL recff_string_rep(jit_State *J, RecordFFData *rd)
emitir(IRTGI(vrep > 1 ? IR_GT : IR_LE), rep, lj_ir_kint(J, 1)); emitir(IRTGI(vrep > 1 ? IR_GT : IR_LE), rep, lj_ir_kint(J, 1));
if (vrep > 1) { if (vrep > 1) {
TRef hdr2 = recff_bufhdr(J); TRef hdr2 = recff_bufhdr(J);
TRef tr2 = emitir(IRT(IR_BUFPUT, IRT_PGC), hdr2, sep); TRef tr2 = emitir(IRTG(IR_BUFPUT, IRT_PGC), hdr2, sep);
tr2 = emitir(IRT(IR_BUFPUT, IRT_PGC), tr2, str); tr2 = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr2, str);
str2 = emitir(IRT(IR_BUFSTR, IRT_STR), tr2, hdr2); str2 = emitir(IRTG(IR_BUFSTR, IRT_STR), tr2, hdr2);
} }
} }
tr = hdr = recff_bufhdr(J); tr = hdr = recff_bufhdr(J);
if (str2) { if (str2) {
tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, str); tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, str);
str = str2; str = str2;
rep = emitir(IRTI(IR_ADD), rep, lj_ir_kint(J, -1)); rep = emitir(IRTI(IR_ADD), rep, lj_ir_kint(J, -1));
} }
tr = lj_ir_call(J, IRCALL_lj_buf_putstr_rep, tr, str, rep); tr = lj_ir_call(J, IRCALL_lj_buf_putstr_rep, tr, str, rep);
J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);
} }
static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd) static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd)
@ -872,7 +872,7 @@ static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd)
TRef str = lj_ir_tostr(J, J->base[0]); TRef str = lj_ir_tostr(J, J->base[0]);
TRef hdr = recff_bufhdr(J); TRef hdr = recff_bufhdr(J);
TRef tr = lj_ir_call(J, rd->data, hdr, str); TRef tr = lj_ir_call(J, rd->data, hdr, str);
J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);
} }
static void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd) static void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd)
@ -953,7 +953,7 @@ static void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd)
IRCallID id; IRCallID id;
switch (STRFMT_TYPE(sf)) { switch (STRFMT_TYPE(sf)) {
case STRFMT_LIT: case STRFMT_LIT:
tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr,
lj_ir_kstr(J, lj_str_new(J->L, fs.str, fs.len))); lj_ir_kstr(J, lj_str_new(J->L, fs.str, fs.len)));
break; break;
case STRFMT_INT: case STRFMT_INT:
@ -962,7 +962,7 @@ static void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd)
if (!tref_isinteger(tra)) if (!tref_isinteger(tra))
goto handle_num; goto handle_num;
if (sf == STRFMT_INT) { /* Shortcut for plain %d. */ if (sf == STRFMT_INT) { /* Shortcut for plain %d. */
tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr,
emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_INT)); emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_INT));
} else { } else {
#if LJ_HASFFI #if LJ_HASFFI
@ -992,7 +992,7 @@ static void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd)
return; return;
} }
if (sf == STRFMT_STR) /* Shortcut for plain %s. */ if (sf == STRFMT_STR) /* Shortcut for plain %s. */
tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, tra); tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, tra);
else if ((sf & STRFMT_T_QUOTED)) else if ((sf & STRFMT_T_QUOTED))
tr = lj_ir_call(J, IRCALL_lj_strfmt_putquoted, tr, tra); tr = lj_ir_call(J, IRCALL_lj_strfmt_putquoted, tr, tra);
else else
@ -1001,7 +1001,7 @@ static void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd)
case STRFMT_CHAR: case STRFMT_CHAR:
tra = lj_opt_narrow_toint(J, tra); tra = lj_opt_narrow_toint(J, tra);
if (sf == STRFMT_CHAR) /* Shortcut for plain %c. */ if (sf == STRFMT_CHAR) /* Shortcut for plain %c. */
tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr,
emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_CHAR)); emitir(IRT(IR_TOSTR, IRT_STR), tra, IRTOSTR_CHAR));
else else
tr = lj_ir_call(J, IRCALL_lj_strfmt_putfchar, tr, trsf, tra); tr = lj_ir_call(J, IRCALL_lj_strfmt_putfchar, tr, trsf, tra);
@ -1013,7 +1013,7 @@ static void LJ_FASTCALL recff_string_format(jit_State *J, RecordFFData *rd)
return; return;
} }
} }
J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);
} }
/* -- Table library fast functions ---------------------------------------- */ /* -- Table library fast functions ---------------------------------------- */
@ -1054,7 +1054,7 @@ static void LJ_FASTCALL recff_table_concat(jit_State *J, RecordFFData *rd)
TRef hdr = recff_bufhdr(J); TRef hdr = recff_bufhdr(J);
TRef tr = lj_ir_call(J, IRCALL_lj_buf_puttab, hdr, tab, sep, tri, tre); TRef tr = lj_ir_call(J, IRCALL_lj_buf_puttab, hdr, tab, sep, tri, tre);
emitir(IRTG(IR_NE, IRT_PTR), tr, lj_ir_kptr(J, NULL)); emitir(IRTG(IR_NE, IRT_PTR), tr, lj_ir_kptr(J, NULL));
J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); J->base[0] = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);
} /* else: Interpreter will throw. */ } /* else: Interpreter will throw. */
UNUSED(rd); UNUSED(rd);
} }

View File

@ -124,8 +124,8 @@
\ \
/* Buffer operations. */ \ /* Buffer operations. */ \
_(BUFHDR, L , ref, lit) \ _(BUFHDR, L , ref, lit) \
_(BUFPUT, L , ref, ref) \ _(BUFPUT, LW, ref, ref) \
_(BUFSTR, A , ref, ref) \ _(BUFSTR, AW, ref, ref) \
\ \
/* Barriers. */ \ /* Barriers. */ \
_(TBAR, S , ref, ___) \ _(TBAR, S , ref, ___) \
@ -139,9 +139,9 @@
_(STRTO, N , ref, ___) \ _(STRTO, N , ref, ___) \
\ \
/* Calls. */ \ /* Calls. */ \
_(CALLN, N , ref, lit) \ _(CALLN, NW, ref, lit) \
_(CALLA, A , ref, lit) \ _(CALLA, AW, ref, lit) \
_(CALLL, L , ref, lit) \ _(CALLL, LW, ref, lit) \
_(CALLS, S , ref, lit) \ _(CALLS, S , ref, lit) \
_(CALLXS, S , ref, ref) \ _(CALLXS, S , ref, ref) \
_(CARG, N , ref, ref) \ _(CARG, N , ref, ref) \

View File

@ -30,10 +30,12 @@ typedef struct CCallInfo {
#define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT) #define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT)
#define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT) #define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT)
#define CCI_CALL_FN (CCI_CALL_N|CCI_CC_FASTCALL) #define CCI_CALL_FN (CCI_CALL_N|CCI_CC_FASTCALL)
#define CCI_CALL_FA (CCI_CALL_A|CCI_CC_FASTCALL)
#define CCI_CALL_FL (CCI_CALL_L|CCI_CC_FASTCALL) #define CCI_CALL_FL (CCI_CALL_L|CCI_CC_FASTCALL)
#define CCI_CALL_FS (CCI_CALL_S|CCI_CC_FASTCALL) #define CCI_CALL_FS (CCI_CALL_S|CCI_CC_FASTCALL)
/* C call info flags. */ /* C call info flags. */
#define CCI_T (IRT_GUARD << CCI_OTSHIFT) /* May throw. */
#define CCI_L 0x0100 /* Implicit L arg. */ #define CCI_L 0x0100 /* Implicit L arg. */
#define CCI_CASTU64 0x0200 /* Cast u64 result to number. */ #define CCI_CASTU64 0x0200 /* Cast u64 result to number. */
#define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */ #define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */
@ -139,39 +141,39 @@ typedef struct CCallInfo {
#define IRCALLDEF(_) \ #define IRCALLDEF(_) \
_(ANY, lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \ _(ANY, lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \
_(ANY, lj_str_find, 4, N, PGC, 0) \ _(ANY, lj_str_find, 4, N, PGC, 0) \
_(ANY, lj_str_new, 3, S, STR, CCI_L) \ _(ANY, lj_str_new, 3, S, STR, CCI_L|CCI_T) \
_(ANY, lj_strscan_num, 2, FN, INT, 0) \ _(ANY, lj_strscan_num, 2, FN, INT, 0) \
_(ANY, lj_strfmt_int, 2, FN, STR, CCI_L) \ _(ANY, lj_strfmt_int, 2, FN, STR, CCI_L|CCI_T) \
_(ANY, lj_strfmt_num, 2, FN, STR, CCI_L) \ _(ANY, lj_strfmt_num, 2, FN, STR, CCI_L|CCI_T) \
_(ANY, lj_strfmt_char, 2, FN, STR, CCI_L) \ _(ANY, lj_strfmt_char, 2, FN, STR, CCI_L|CCI_T) \
_(ANY, lj_strfmt_putint, 2, FL, PGC, 0) \ _(ANY, lj_strfmt_putint, 2, FL, PGC, CCI_T) \
_(ANY, lj_strfmt_putnum, 2, FL, PGC, 0) \ _(ANY, lj_strfmt_putnum, 2, FL, PGC, CCI_T) \
_(ANY, lj_strfmt_putquoted, 2, FL, PGC, 0) \ _(ANY, lj_strfmt_putquoted, 2, FL, PGC, CCI_T) \
_(ANY, lj_strfmt_putfxint, 3, L, PGC, XA_64) \ _(ANY, lj_strfmt_putfxint, 3, L, PGC, XA_64|CCI_T) \
_(ANY, lj_strfmt_putfnum_int, 3, L, PGC, XA_FP) \ _(ANY, lj_strfmt_putfnum_int, 3, L, PGC, XA_FP|CCI_T) \
_(ANY, lj_strfmt_putfnum_uint, 3, L, PGC, XA_FP) \ _(ANY, lj_strfmt_putfnum_uint, 3, L, PGC, XA_FP|CCI_T) \
_(ANY, lj_strfmt_putfnum, 3, L, PGC, XA_FP) \ _(ANY, lj_strfmt_putfnum, 3, L, PGC, XA_FP|CCI_T) \
_(ANY, lj_strfmt_putfstr, 3, L, PGC, 0) \ _(ANY, lj_strfmt_putfstr, 3, L, PGC, CCI_T) \
_(ANY, lj_strfmt_putfchar, 3, L, PGC, 0) \ _(ANY, lj_strfmt_putfchar, 3, L, PGC, CCI_T) \
_(ANY, lj_buf_putmem, 3, S, PGC, 0) \ _(ANY, lj_buf_putmem, 3, S, PGC, CCI_T) \
_(ANY, lj_buf_putstr, 2, FL, PGC, 0) \ _(ANY, lj_buf_putstr, 2, FL, PGC, CCI_T) \
_(ANY, lj_buf_putchar, 2, FL, PGC, 0) \ _(ANY, lj_buf_putchar, 2, FL, PGC, CCI_T) \
_(ANY, lj_buf_putstr_reverse, 2, FL, PGC, 0) \ _(ANY, lj_buf_putstr_reverse, 2, FL, PGC, CCI_T) \
_(ANY, lj_buf_putstr_lower, 2, FL, PGC, 0) \ _(ANY, lj_buf_putstr_lower, 2, FL, PGC, CCI_T) \
_(ANY, lj_buf_putstr_upper, 2, FL, PGC, 0) \ _(ANY, lj_buf_putstr_upper, 2, FL, PGC, CCI_T) \
_(ANY, lj_buf_putstr_rep, 3, L, PGC, 0) \ _(ANY, lj_buf_putstr_rep, 3, L, PGC, CCI_T) \
_(ANY, lj_buf_puttab, 5, L, PGC, 0) \ _(ANY, lj_buf_puttab, 5, L, PGC, CCI_T) \
_(ANY, lj_buf_tostr, 1, FL, STR, 0) \ _(ANY, lj_buf_tostr, 1, FL, STR, CCI_T) \
_(ANY, lj_tab_new_ah, 3, A, TAB, CCI_L) \ _(ANY, lj_tab_new_ah, 3, A, TAB, CCI_L|CCI_T) \
_(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \ _(ANY, lj_tab_new1, 2, FA, TAB, CCI_L|CCI_T) \
_(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \ _(ANY, lj_tab_dup, 2, FA, TAB, CCI_L|CCI_T) \
_(ANY, lj_tab_clear, 1, FS, NIL, 0) \ _(ANY, lj_tab_clear, 1, FS, NIL, 0) \
_(ANY, lj_tab_newkey, 3, S, PGC, CCI_L) \ _(ANY, lj_tab_newkey, 3, S, PGC, CCI_L|CCI_T) \
_(ANY, lj_tab_len, 1, FL, INT, 0) \ _(ANY, lj_tab_len, 1, FL, INT, 0) \
_(ANY, lj_tab_len_hint, 2, FL, INT, 0) \ _(ANY, lj_tab_len_hint, 2, FL, INT, 0) \
_(ANY, lj_gc_step_jit, 2, FS, NIL, CCI_L) \ _(ANY, lj_gc_step_jit, 2, FS, NIL, CCI_L) \
_(ANY, lj_gc_barrieruv, 2, FS, NIL, 0) \ _(ANY, lj_gc_barrieruv, 2, FS, NIL, 0) \
_(ANY, lj_mem_newgco, 2, FS, PGC, CCI_L) \ _(ANY, lj_mem_newgco, 2, FA, PGC, CCI_L|CCI_T) \
_(ANY, lj_prng_u64d, 1, FS, NUM, CCI_CASTU64) \ _(ANY, lj_prng_u64d, 1, FS, NUM, CCI_CASTU64) \
_(ANY, lj_vm_modi, 2, FN, INT, 0) \ _(ANY, lj_vm_modi, 2, FN, INT, 0) \
_(ANY, log10, 1, N, NUM, XA_FP) \ _(ANY, log10, 1, N, NUM, XA_FP) \

View File

@ -1935,9 +1935,9 @@ static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot)
tr = hdr = emitir(IRT(IR_BUFHDR, IRT_PGC), tr = hdr = emitir(IRT(IR_BUFHDR, IRT_PGC),
lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);
do { do {
tr = emitir(IRT(IR_BUFPUT, IRT_PGC), tr, *trp++); tr = emitir(IRTG(IR_BUFPUT, IRT_PGC), tr, *trp++);
} while (trp <= top); } while (trp <= top);
tr = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); tr = emitir(IRTG(IR_BUFSTR, IRT_STR), tr, hdr);
J->maxslot = (BCReg)(xbase - J->base); J->maxslot = (BCReg)(xbase - J->base);
if (xbase == base) return tr; /* Return simple concatenation result. */ if (xbase == base) return tr; /* Return simple concatenation result. */
/* Pass partial result. */ /* Pass partial result. */