diff options
author | Mike Pall <mike> | 2013-04-26 00:32:08 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-04-26 00:32:08 +0200 |
commit | b6adfff8f4e388ea286ca4d7d8e0896c07f1cab8 (patch) | |
tree | 26dc6763ae0378b1f783d644eff8f4662679a1d4 | |
parent | 61cb25b0ca19f75be49373969d6dc3daa646d3aa (diff) | |
download | luajit-b6adfff8f4e388ea286ca4d7d8e0896c07f1cab8.tar.gz luajit-b6adfff8f4e388ea286ca4d7d8e0896c07f1cab8.tar.bz2 luajit-b6adfff8f4e388ea286ca4d7d8e0896c07f1cab8.zip |
Compile string.reverse(), string.lower(), string.upper().
-rw-r--r-- | src/Makefile.dep | 6 | ||||
-rw-r--r-- | src/lib_string.c | 6 | ||||
-rw-r--r-- | src/lj_ffrecord.c | 9 | ||||
-rw-r--r-- | src/lj_ircall.h | 3 | ||||
-rw-r--r-- | src/lj_opt_fold.c | 26 |
5 files changed, 42 insertions, 8 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index a29b396a..6747e599 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
@@ -143,9 +143,9 @@ lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h | |||
143 | lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 143 | lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
144 | lj_ir.h lj_jit.h lj_iropt.h | 144 | lj_ir.h lj_jit.h lj_iropt.h |
145 | lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 145 | lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
146 | lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h \ | 146 | lj_buf.h lj_gc.h lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h \ |
147 | lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_carith.h \ | 147 | lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h \ |
148 | lj_vm.h lj_strscan.h lj_folddef.h | 148 | lj_carith.h lj_vm.h lj_strscan.h lj_folddef.h |
149 | lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 149 | lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
150 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \ | 150 | lj_err.h lj_errmsg.h lj_buf.h lj_gc.h lj_str.h lj_ir.h lj_jit.h \ |
151 | lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \ | 151 | lj_iropt.h lj_trace.h lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h \ |
diff --git a/src/lib_string.c b/src/lib_string.c index c8243d6c..f3c29aa7 100644 --- a/src/lib_string.c +++ b/src/lib_string.c | |||
@@ -133,13 +133,13 @@ LJLIB_ASM(string_rep) | |||
133 | return FFH_RES(1); | 133 | return FFH_RES(1); |
134 | } | 134 | } |
135 | 135 | ||
136 | LJLIB_ASM(string_reverse) | 136 | LJLIB_ASM(string_reverse) LJLIB_REC(string_op IRCALL_lj_buf_putstr_reverse) |
137 | { | 137 | { |
138 | lj_lib_checkstr(L, 1); | 138 | lj_lib_checkstr(L, 1); |
139 | return FFH_RETRY; | 139 | return FFH_RETRY; |
140 | } | 140 | } |
141 | LJLIB_ASM_(string_lower) | 141 | LJLIB_ASM_(string_lower) LJLIB_REC(string_op IRCALL_lj_buf_putstr_lower) |
142 | LJLIB_ASM_(string_upper) | 142 | LJLIB_ASM_(string_upper) LJLIB_REC(string_op IRCALL_lj_buf_putstr_upper) |
143 | 143 | ||
144 | /* ------------------------------------------------------------------------ */ | 144 | /* ------------------------------------------------------------------------ */ |
145 | 145 | ||
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 191974ea..69423760 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -771,6 +771,15 @@ static void LJ_FASTCALL recff_string_char(jit_State *J, RecordFFData *rd) | |||
771 | UNUSED(rd); | 771 | UNUSED(rd); |
772 | } | 772 | } |
773 | 773 | ||
774 | static void LJ_FASTCALL recff_string_op(jit_State *J, RecordFFData *rd) | ||
775 | { | ||
776 | TRef str = lj_ir_tostr(J, J->base[0]); | ||
777 | TRef hdr = emitir(IRT(IR_BUFHDR, IRT_P32), | ||
778 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
779 | TRef tr = lj_ir_call(J, rd->data, hdr, str); | ||
780 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), hdr, tr); | ||
781 | } | ||
782 | |||
774 | /* -- Table library fast functions ---------------------------------------- */ | 783 | /* -- Table library fast functions ---------------------------------------- */ |
775 | 784 | ||
776 | static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) | 785 | static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd) |
diff --git a/src/lj_ircall.h b/src/lj_ircall.h index 456f89ac..35c063c4 100644 --- a/src/lj_ircall.h +++ b/src/lj_ircall.h | |||
@@ -111,6 +111,9 @@ typedef struct CCallInfo { | |||
111 | _(ANY, lj_buf_putchar, 2, FS, P32, 0) \ | 111 | _(ANY, lj_buf_putchar, 2, FS, P32, 0) \ |
112 | _(ANY, lj_buf_putint, 2, FS, P32, 0) \ | 112 | _(ANY, lj_buf_putint, 2, FS, P32, 0) \ |
113 | _(ANY, lj_buf_putnum, 2, FS, P32, 0) \ | 113 | _(ANY, lj_buf_putnum, 2, FS, P32, 0) \ |
114 | _(ANY, lj_buf_putstr_reverse, 2, FS, P32, 0) \ | ||
115 | _(ANY, lj_buf_putstr_lower, 2, FS, P32, 0) \ | ||
116 | _(ANY, lj_buf_putstr_upper, 2, FS, P32, 0) \ | ||
114 | _(ANY, lj_buf_tostr, 1, FL, STR, 0) \ | 117 | _(ANY, lj_buf_tostr, 1, FL, STR, 0) \ |
115 | _(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \ | 118 | _(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \ |
116 | _(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \ | 119 | _(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \ |
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index 2ed0bc93..91e9655a 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "lj_tab.h" | 19 | #include "lj_tab.h" |
20 | #include "lj_ir.h" | 20 | #include "lj_ir.h" |
21 | #include "lj_jit.h" | 21 | #include "lj_jit.h" |
22 | #include "lj_ircall.h" | ||
22 | #include "lj_iropt.h" | 23 | #include "lj_iropt.h" |
23 | #include "lj_trace.h" | 24 | #include "lj_trace.h" |
24 | #if LJ_HASFFI | 25 | #if LJ_HASFFI |
@@ -570,7 +571,8 @@ LJFOLDF(bufput_kgc) | |||
570 | LJFOLD(BUFSTR any any) | 571 | LJFOLD(BUFSTR any any) |
571 | LJFOLDF(bufstr_kfold_cse) | 572 | LJFOLDF(bufstr_kfold_cse) |
572 | { | 573 | { |
573 | lua_assert(fright->o == IR_BUFHDR || fright->o == IR_BUFPUT); | 574 | lua_assert(fright->o == IR_BUFHDR || fright->o == IR_BUFPUT || |
575 | fright->o == IR_CALLS); | ||
574 | if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { | 576 | if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) { |
575 | if (fright->o == IR_BUFHDR) { /* No put operations? */ | 577 | if (fright->o == IR_BUFHDR) { /* No put operations? */ |
576 | if (!(fright->op2 & IRBUFHDR_APPEND)) { /* Empty buffer? */ | 578 | if (!(fright->op2 & IRBUFHDR_APPEND)) { /* Empty buffer? */ |
@@ -579,7 +581,7 @@ LJFOLDF(bufstr_kfold_cse) | |||
579 | } | 581 | } |
580 | fins->op2 = fright->prev; /* Relies on checks in bufput_append. */ | 582 | fins->op2 = fright->prev; /* Relies on checks in bufput_append. */ |
581 | return CSEFOLD; | 583 | return CSEFOLD; |
582 | } else { | 584 | } else if (fright->o == IR_BUFPUT) { |
583 | IRIns *irb = IR(fright->op1); | 585 | IRIns *irb = IR(fright->op1); |
584 | if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND)) { | 586 | if (irb->o == IR_BUFHDR && !(irb->op2 & IRBUFHDR_APPEND)) { |
585 | lj_ir_rollback(J, fins->op1); /* Eliminate the current chain. */ | 587 | lj_ir_rollback(J, fins->op1); /* Eliminate the current chain. */ |
@@ -616,6 +618,26 @@ LJFOLDF(bufstr_kfold_cse) | |||
616 | return EMITFOLD; /* No CSE possible. */ | 618 | return EMITFOLD; /* No CSE possible. */ |
617 | } | 619 | } |
618 | 620 | ||
621 | LJFOLD(CALLS CARG IRCALL_lj_buf_putstr_reverse) | ||
622 | LJFOLD(CALLS CARG IRCALL_lj_buf_putstr_upper) | ||
623 | LJFOLD(CALLS CARG IRCALL_lj_buf_putstr_lower) | ||
624 | LJFOLDF(bufput_kfold_op) | ||
625 | { | ||
626 | if (irref_isk(fleft->op2)) { | ||
627 | const CCallInfo *ci = &lj_ir_callinfo[fins->op2]; | ||
628 | SBuf *sb = &J2G(J)->tmpbuf; | ||
629 | setsbufL(sb, J->L); | ||
630 | lj_buf_reset(sb); | ||
631 | sb = ((SBuf * LJ_FASTCALL (*)(SBuf *, GCstr *))ci->func)(sb, | ||
632 | ir_kstr(IR(fleft->op2))); | ||
633 | fins->op2 = lj_ir_kstr(J, lj_buf_tostr(sb)); | ||
634 | fins->op1 = fleft->op1; | ||
635 | fins->o = IR_BUFPUT; | ||
636 | return RETRYFOLD; | ||
637 | } | ||
638 | return EMITFOLD; /* This is a store and always emitted. */ | ||
639 | } | ||
640 | |||
619 | /* -- Constant folding of pointer arithmetic ------------------------------ */ | 641 | /* -- Constant folding of pointer arithmetic ------------------------------ */ |
620 | 642 | ||
621 | LJFOLD(ADD KGC KINT) | 643 | LJFOLD(ADD KGC KINT) |