]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Compile string.reverse(), string.lower(), string.upper().
authorMike Pall <mike>
Thu, 25 Apr 2013 22:32:08 +0000 (00:32 +0200)
committerMike Pall <mike>
Thu, 25 Apr 2013 22:32:08 +0000 (00:32 +0200)
src/Makefile.dep
src/lib_string.c
src/lj_ffrecord.c
src/lj_ircall.h
src/lj_opt_fold.c

index a29b396a18664f5b87462cd3a63cf305b22af286..6747e599c97c15bf3b4a5df1cec665ff3d071a43 100644 (file)
@@ -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_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_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h \
- lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_carith.h \
- lj_vm.h lj_strscan.h lj_folddef.h
+ lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h \
+ lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.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_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 \
index c8243d6c847cc92b685a5acd7c0786ed65c4d545..f3c29aa7474deb0489ddab1826e8c26a640b7bf1 100644 (file)
@@ -133,13 +133,13 @@ LJLIB_ASM(string_rep)
   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);
   return FFH_RETRY;
 }
-LJLIB_ASM_(string_lower)
-LJLIB_ASM_(string_upper)
+LJLIB_ASM_(string_lower)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_lower)
+LJLIB_ASM_(string_upper)  LJLIB_REC(string_op IRCALL_lj_buf_putstr_upper)
 
 /* ------------------------------------------------------------------------ */
 
index 191974ea10abe1e9dd7efdc93eda67a5265e1b1e..694237605327dad798b6071e477c404fb2968d9d 100644 (file)
@@ -771,6 +771,15 @@ static void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *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 ---------------------------------------- */
 
 static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd)
index 456f89ac58cc7e189580c9715c11bd0fd9cd5f09..35c063c45c44f6d68f07b6a3fe978623a92654ad 100644 (file)
@@ -111,6 +111,9 @@ typedef struct CCallInfo {
   _(ANY,       lj_buf_putchar,         2,  FS, P32, 0) \
   _(ANY,       lj_buf_putint,          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_tab_new1,            2,  FS, TAB, CCI_L) \
   _(ANY,       lj_tab_dup,             2,  FS, TAB, CCI_L) \
index 2ed0bc93970119759d0b7cec4650fd28aa351fa5..91e9655a6abd16bef5a3a05ca6c6e8b859200bc7 100644 (file)
@@ -19,6 +19,7 @@
 #include "lj_tab.h"
 #include "lj_ir.h"
 #include "lj_jit.h"
+#include "lj_ircall.h"
 #include "lj_iropt.h"
 #include "lj_trace.h"
 #if LJ_HASFFI
@@ -570,7 +571,8 @@ LJFOLDF(bufput_kgc)
 LJFOLD(BUFSTR any any)
 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 (fright->o == IR_BUFHDR) {  /* No put operations? */
       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. */
       return CSEFOLD;
-    } else {
+    } else if (fright->o == IR_BUFPUT) {
       IRIns *irb = IR(fright->op1);
       if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND)) {
        lj_ir_rollback(J, fins->op1);  /* Eliminate the current chain. */
@@ -616,6 +618,26 @@ LJFOLDF(bufstr_kfold_cse)
   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 ------------------------------ */
 
 LJFOLD(ADD KGC KINT)