mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
Compile string.reverse(), string.lower(), string.upper().
This commit is contained in:
parent
61cb25b0ca
commit
b6adfff8f4
@ -143,9 +143,9 @@ lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h
|
|||||||
lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
lj_ir.h lj_jit.h lj_iropt.h
|
lj_ir.h lj_jit.h lj_iropt.h
|
||||||
lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h \
|
lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h \
|
||||||
lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_carith.h \
|
lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h \
|
||||||
lj_vm.h lj_strscan.h lj_folddef.h
|
lj_carith.h lj_vm.h lj_strscan.h lj_folddef.h
|
||||||
lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
|
||||||
lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \
|
lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \
|
||||||
lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \
|
lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \
|
||||||
|
@ -133,13 +133,13 @@ LJLIB_ASM(string_rep)
|
|||||||
return FFH_RES(1);
|
return FFH_RES(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
LJLIB_ASM(string_reverse)
|
LJLIB_ASM(string_reverse) LJLIB_REC(string_op IRCALL_lj_buf_putstr_reverse)
|
||||||
{
|
{
|
||||||
lj_lib_checkstr(L, 1);
|
lj_lib_checkstr(L, 1);
|
||||||
return FFH_RETRY;
|
return FFH_RETRY;
|
||||||
}
|
}
|
||||||
LJLIB_ASM_(string_lower)
|
LJLIB_ASM_(string_lower) LJLIB_REC(string_op IRCALL_lj_buf_putstr_lower)
|
||||||
LJLIB_ASM_(string_upper)
|
LJLIB_ASM_(string_upper) LJLIB_REC(string_op IRCALL_lj_buf_putstr_upper)
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
@ -771,6 +771,15 @@ static void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd)
|
|||||||
UNUSED(rd);
|
UNUSED(rd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd)
|
||||||
|
{
|
||||||
|
TRef str = lj_ir_tostr(J, J->base[0]);
|
||||||
|
TRef hdr = emitir(IRT(IR_BUFHDR, IRT_P32),
|
||||||
|
lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);
|
||||||
|
TRef tr = lj_ir_call(J, rd->data, hdr, str);
|
||||||
|
J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), hdr, tr);
|
||||||
|
}
|
||||||
|
|
||||||
/* -- Table library fast functions ---------------------------------------- */
|
/* -- Table library fast functions ---------------------------------------- */
|
||||||
|
|
||||||
static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd)
|
static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd)
|
||||||
|
@ -111,6 +111,9 @@ typedef struct CCallInfo {
|
|||||||
_(ANY, lj_buf_putchar, 2, FS, P32, 0) \
|
_(ANY, lj_buf_putchar, 2, FS, P32, 0) \
|
||||||
_(ANY, lj_buf_putint, 2, FS, P32, 0) \
|
_(ANY, lj_buf_putint, 2, FS, P32, 0) \
|
||||||
_(ANY, lj_buf_putnum, 2, FS, P32, 0) \
|
_(ANY, lj_buf_putnum, 2, FS, P32, 0) \
|
||||||
|
_(ANY, lj_buf_putstr_reverse, 2, FS, P32, 0) \
|
||||||
|
_(ANY, lj_buf_putstr_lower, 2, FS, P32, 0) \
|
||||||
|
_(ANY, lj_buf_putstr_upper, 2, FS, P32, 0) \
|
||||||
_(ANY, lj_buf_tostr, 1, FL, STR, 0) \
|
_(ANY, lj_buf_tostr, 1, FL, STR, 0) \
|
||||||
_(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \
|
_(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \
|
||||||
_(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \
|
_(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "lj_tab.h"
|
#include "lj_tab.h"
|
||||||
#include "lj_ir.h"
|
#include "lj_ir.h"
|
||||||
#include "lj_jit.h"
|
#include "lj_jit.h"
|
||||||
|
#include "lj_ircall.h"
|
||||||
#include "lj_iropt.h"
|
#include "lj_iropt.h"
|
||||||
#include "lj_trace.h"
|
#include "lj_trace.h"
|
||||||
#if LJ_HASFFI
|
#if LJ_HASFFI
|
||||||
@ -570,7 +571,8 @@ LJFOLDF(bufput_kgc)
|
|||||||
LJFOLD(BUFSTR any any)
|
LJFOLD(BUFSTR any any)
|
||||||
LJFOLDF(bufstr_kfold_cse)
|
LJFOLDF(bufstr_kfold_cse)
|
||||||
{
|
{
|
||||||
lua_assert(fright->o == IR_BUFHDR || fright->o == IR_BUFPUT);
|
lua_assert(fright->o == IR_BUFHDR || fright->o == IR_BUFPUT ||
|
||||||
|
fright->o == IR_CALLS);
|
||||||
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
|
if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
|
||||||
if (fright->o == IR_BUFHDR) { /* No put operations? */
|
if (fright->o == IR_BUFHDR) { /* No put operations? */
|
||||||
if (!(fright->op2 & IRBUFHDR_APPEND)) { /* Empty buffer? */
|
if (!(fright->op2 & IRBUFHDR_APPEND)) { /* Empty buffer? */
|
||||||
@ -579,7 +581,7 @@ LJFOLDF(bufstr_kfold_cse)
|
|||||||
}
|
}
|
||||||
fins->op2 = fright->prev; /* Relies on checks in bufput_append. */
|
fins->op2 = fright->prev; /* Relies on checks in bufput_append. */
|
||||||
return CSEFOLD;
|
return CSEFOLD;
|
||||||
} else {
|
} else if (fright->o == IR_BUFPUT) {
|
||||||
IRIns *irb = IR(fright->op1);
|
IRIns *irb = IR(fright->op1);
|
||||||
if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND)) {
|
if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND)) {
|
||||||
lj_ir_rollback(J, fins->op1); /* Eliminate the current chain. */
|
lj_ir_rollback(J, fins->op1); /* Eliminate the current chain. */
|
||||||
@ -616,6 +618,26 @@ LJFOLDF(bufstr_kfold_cse)
|
|||||||
return EMITFOLD; /* No CSE possible. */
|
return EMITFOLD; /* No CSE possible. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LJFOLD(CALLS CARG IRCALL_lj_buf_putstr_reverse)
|
||||||
|
LJFOLD(CALLS CARG IRCALL_lj_buf_putstr_upper)
|
||||||
|
LJFOLD(CALLS CARG IRCALL_lj_buf_putstr_lower)
|
||||||
|
LJFOLDF(bufput_kfold_op)
|
||||||
|
{
|
||||||
|
if (irref_isk(fleft->op2)) {
|
||||||
|
const CCallInfo *ci = &lj_ir_callinfo[fins->op2];
|
||||||
|
SBuf *sb = &J2G(J)->tmpbuf;
|
||||||
|
setsbufL(sb, J->L);
|
||||||
|
lj_buf_reset(sb);
|
||||||
|
sb = ((SBuf * LJ_FASTCALL (*)(SBuf *, GCstr *))ci->func)(sb,
|
||||||
|
ir_kstr(IR(fleft->op2)));
|
||||||
|
fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb));
|
||||||
|
fins->op1 = fleft->op1;
|
||||||
|
fins->o = IR_BUFPUT;
|
||||||
|
return RETRYFOLD;
|
||||||
|
}
|
||||||
|
return EMITFOLD; /* This is a store and always emitted. */
|
||||||
|
}
|
||||||
|
|
||||||
/* -- Constant folding of pointer arithmetic ------------------------------ */
|
/* -- Constant folding of pointer arithmetic ------------------------------ */
|
||||||
|
|
||||||
LJFOLD(ADD KGC KINT)
|
LJFOLD(ADD KGC KINT)
|
||||||
|
Loading…
Reference in New Issue
Block a user