mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Enable tracing of recursion.
Now compiles tail-recursion, up-recursion and down-recursion. Benchmarks vs. Lua: fib 20x, ack 23x, binary-trees 4.7x.
This commit is contained in:
parent
e7b737aa12
commit
5d0b65519c
@ -136,10 +136,6 @@ with me, before writing major improvements, to avoid duplication of
|
||||
effort.
|
||||
</li>
|
||||
<li>
|
||||
<b>Recursion</b> is not traced yet. Often no trace will be generated at
|
||||
all or some unroll limit will catch it and abort the trace.
|
||||
</li>
|
||||
<li>
|
||||
The trace compiler currently does not back off specialization for
|
||||
function call dispatch. It should really fall back to specializing on
|
||||
the prototype, not the closure identity. This can lead to the so-called
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define DASM_SECTION_CODE_OP 0
|
||||
#define DASM_SECTION_CODE_SUB 1
|
||||
#define DASM_MAXSECTION 2
|
||||
static const unsigned char build_actionlist[14028] = {
|
||||
static const unsigned char build_actionlist[14049] = {
|
||||
254,1,248,10,252,247,195,237,15,132,244,11,131,227,252,248,41,218,72,141,
|
||||
76,25,252,248,139,90,252,252,199,68,10,4,237,248,12,131,192,1,137,68,36,4,
|
||||
252,247,195,237,15,132,244,13,248,14,252,247,195,237,15,132,244,10,65,199,
|
||||
@ -676,8 +676,9 @@ static const unsigned char build_actionlist[14028] = {
|
||||
233,139,4,193,72,139,128,233,139,108,36,24,65,137,150,233,65,137,174,233,
|
||||
76,137,36,36,76,137,108,36,8,72,131,252,236,16,252,255,224,255,141,156,253,
|
||||
131,233,139,3,15,182,204,15,182,232,131,195,4,193,232,16,65,252,255,36,252,
|
||||
238,255,68,139,187,233,139,108,36,24,141,12,202,59,141,233,15,135,244,23,
|
||||
15,182,139,233,57,200,15,134,244,249,248,2,255,15,183,67,252,254,252,233,
|
||||
238,255,137,221,209,252,237,129,229,239,102,65,131,172,253,46,233,1,15,132,
|
||||
244,142,255,68,139,187,233,139,108,36,24,141,12,202,59,141,233,15,135,244,
|
||||
23,15,182,139,233,57,200,15,134,244,249,248,2,255,15,183,67,252,254,252,233,
|
||||
245,255,248,3,199,68,194,252,252,237,131,192,1,57,200,15,134,244,3,252,233,
|
||||
244,2,255,141,44,197,237,141,4,194,68,139,122,252,248,137,104,252,252,68,
|
||||
137,120,252,248,139,108,36,24,141,12,200,59,141,233,15,135,244,22,137,209,
|
||||
@ -2150,6 +2151,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
|
||||
case BC_FUNCF:
|
||||
#if LJ_HASJIT
|
||||
dasm_put(Dst, 13731, HOTCOUNT_PCMASK, GG_DISP2HOT);
|
||||
#endif
|
||||
case BC_FUNCV: /* NYI: compiled vararg functions. */
|
||||
break;
|
||||
@ -2159,13 +2161,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
break;
|
||||
#endif
|
||||
case BC_IFUNCF:
|
||||
dasm_put(Dst, 13731, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
|
||||
dasm_put(Dst, 13752, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
|
||||
if (op == BC_JFUNCF) {
|
||||
dasm_put(Dst, 13762, BC_JLOOP);
|
||||
dasm_put(Dst, 13783, BC_JLOOP);
|
||||
} else {
|
||||
dasm_put(Dst, 9531);
|
||||
}
|
||||
dasm_put(Dst, 13771, LJ_TNIL);
|
||||
dasm_put(Dst, 13792, LJ_TNIL);
|
||||
break;
|
||||
|
||||
case BC_JFUNCV:
|
||||
@ -2176,30 +2178,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
break; /* NYI: compiled vararg functions. */
|
||||
|
||||
case BC_IFUNCV:
|
||||
dasm_put(Dst, 13793, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
|
||||
dasm_put(Dst, 13814, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
|
||||
if (op == BC_JFUNCV) {
|
||||
dasm_put(Dst, 13762, BC_JLOOP);
|
||||
dasm_put(Dst, 13783, BC_JLOOP);
|
||||
} else {
|
||||
dasm_put(Dst, 13890, -4+PC2PROTO(k));
|
||||
dasm_put(Dst, 13911, -4+PC2PROTO(k));
|
||||
}
|
||||
dasm_put(Dst, 13915, LJ_TNIL);
|
||||
dasm_put(Dst, 13936, LJ_TNIL);
|
||||
break;
|
||||
|
||||
case BC_FUNCC:
|
||||
case BC_FUNCCW:
|
||||
dasm_put(Dst, 13937, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
|
||||
dasm_put(Dst, 13958, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 13967);
|
||||
dasm_put(Dst, 13988);
|
||||
} else {
|
||||
dasm_put(Dst, 13971);
|
||||
dasm_put(Dst, 13992);
|
||||
}
|
||||
dasm_put(Dst, 13979, DISPATCH_GL(vmstate), ~LJ_VMST_C);
|
||||
dasm_put(Dst, 14000, DISPATCH_GL(vmstate), ~LJ_VMST_C);
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 13989);
|
||||
dasm_put(Dst, 14010);
|
||||
} else {
|
||||
dasm_put(Dst, 13994, DISPATCH_GL(wrapf));
|
||||
dasm_put(Dst, 14015, DISPATCH_GL(wrapf));
|
||||
}
|
||||
dasm_put(Dst, 14000, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
|
||||
dasm_put(Dst, 14021, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
|
||||
break;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -2227,7 +2229,7 @@ static int build_backend(BuildCtx *ctx)
|
||||
|
||||
build_subroutines(ctx, cmov, sse);
|
||||
|
||||
dasm_put(Dst, 14026);
|
||||
dasm_put(Dst, 14047);
|
||||
for (op = 0; op < BC__MAX; op++)
|
||||
build_ins(ctx, (BCOp)op, op, cmov, sse);
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define DASM_SECTION_CODE_OP 0
|
||||
#define DASM_SECTION_CODE_SUB 1
|
||||
#define DASM_MAXSECTION 2
|
||||
static const unsigned char build_actionlist[13976] = {
|
||||
static const unsigned char build_actionlist[13997] = {
|
||||
254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,72,
|
||||
141,76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,137,68,
|
||||
36,84,252,247,198,237,15,132,244,13,248,14,252,247,198,237,15,132,244,10,
|
||||
@ -676,9 +676,10 @@ static const unsigned char build_actionlist[13976] = {
|
||||
233,102,68,15,127,129,233,102,68,15,127,137,233,102,68,15,127,145,233,102,
|
||||
68,15,127,153,233,102,68,15,127,161,233,102,68,15,127,169,233,102,68,15,127,
|
||||
177,233,102,68,15,127,185,233,252,255,224,255,141,180,253,134,233,139,6,15,
|
||||
182,204,15,182,232,131,198,4,193,232,16,252,255,36,252,235,255,139,190,233,
|
||||
139,108,36,96,141,12,202,59,141,233,15,135,244,23,15,182,142,233,57,200,15,
|
||||
134,244,249,248,2,255,15,183,70,252,254,252,233,245,255,248,3,199,68,194,
|
||||
182,204,15,182,232,131,198,4,193,232,16,252,255,36,252,235,255,137,252,245,
|
||||
209,252,237,129,229,239,102,131,172,253,43,233,1,15,132,244,142,255,139,190,
|
||||
233,139,108,36,96,141,12,202,59,141,233,15,135,244,23,15,182,142,233,57,200,
|
||||
15,134,244,249,248,2,255,15,183,70,252,254,252,233,245,255,248,3,199,68,194,
|
||||
252,252,237,131,192,1,57,200,15,134,244,3,252,233,244,2,255,141,44,197,237,
|
||||
141,4,194,139,122,252,248,137,104,252,252,137,120,252,248,139,108,36,96,141,
|
||||
12,200,59,141,233,15,135,244,22,137,209,137,194,15,182,174,233,133,252,237,
|
||||
@ -2150,6 +2151,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
|
||||
case BC_FUNCF:
|
||||
#if LJ_HASJIT
|
||||
dasm_put(Dst, 13692, HOTCOUNT_PCMASK, GG_DISP2HOT);
|
||||
#endif
|
||||
case BC_FUNCV: /* NYI: compiled vararg functions. */
|
||||
break;
|
||||
@ -2159,13 +2161,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
break;
|
||||
#endif
|
||||
case BC_IFUNCF:
|
||||
dasm_put(Dst, 13692, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
|
||||
dasm_put(Dst, 13713, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
|
||||
if (op == BC_JFUNCF) {
|
||||
dasm_put(Dst, 13722, BC_JLOOP);
|
||||
dasm_put(Dst, 13743, BC_JLOOP);
|
||||
} else {
|
||||
dasm_put(Dst, 9539);
|
||||
}
|
||||
dasm_put(Dst, 13731, LJ_TNIL);
|
||||
dasm_put(Dst, 13752, LJ_TNIL);
|
||||
break;
|
||||
|
||||
case BC_JFUNCV:
|
||||
@ -2176,30 +2178,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
break; /* NYI: compiled vararg functions. */
|
||||
|
||||
case BC_IFUNCV:
|
||||
dasm_put(Dst, 13753, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
|
||||
dasm_put(Dst, 13774, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
|
||||
if (op == BC_JFUNCV) {
|
||||
dasm_put(Dst, 13722, BC_JLOOP);
|
||||
dasm_put(Dst, 13743, BC_JLOOP);
|
||||
} else {
|
||||
dasm_put(Dst, 13844, -4+PC2PROTO(k));
|
||||
dasm_put(Dst, 13865, -4+PC2PROTO(k));
|
||||
}
|
||||
dasm_put(Dst, 13867, LJ_TNIL);
|
||||
dasm_put(Dst, 13888, LJ_TNIL);
|
||||
break;
|
||||
|
||||
case BC_FUNCC:
|
||||
case BC_FUNCCW:
|
||||
dasm_put(Dst, 13889, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 13919);
|
||||
} else {
|
||||
dasm_put(Dst, 13923);
|
||||
}
|
||||
dasm_put(Dst, 13931, DISPATCH_GL(vmstate), ~LJ_VMST_C);
|
||||
dasm_put(Dst, 13910, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 13940);
|
||||
} else {
|
||||
dasm_put(Dst, 13944, DISPATCH_GL(wrapf));
|
||||
dasm_put(Dst, 13944);
|
||||
}
|
||||
dasm_put(Dst, 13949, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
|
||||
dasm_put(Dst, 13952, DISPATCH_GL(vmstate), ~LJ_VMST_C);
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 13961);
|
||||
} else {
|
||||
dasm_put(Dst, 13965, DISPATCH_GL(wrapf));
|
||||
}
|
||||
dasm_put(Dst, 13970, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
|
||||
break;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -2227,7 +2229,7 @@ static int build_backend(BuildCtx *ctx)
|
||||
|
||||
build_subroutines(ctx, cmov, sse);
|
||||
|
||||
dasm_put(Dst, 13974);
|
||||
dasm_put(Dst, 13995);
|
||||
for (op = 0; op < BC__MAX; op++)
|
||||
build_ins(ctx, (BCOp)op, op, cmov, sse);
|
||||
|
||||
|
@ -4790,8 +4790,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
|
||||
case BC_FUNCF:
|
||||
#if LJ_HASJIT
|
||||
| // NYI: Disabled, until the tracer supports recursion/upcalls/leaves.
|
||||
| // hotcall RB
|
||||
| hotcall RB
|
||||
#endif
|
||||
case BC_FUNCV: /* NYI: compiled vararg functions. */
|
||||
| // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define DASM_SECTION_CODE_OP 0
|
||||
#define DASM_SECTION_CODE_SUB 1
|
||||
#define DASM_MAXSECTION 2
|
||||
static const unsigned char build_actionlist[15177] = {
|
||||
static const unsigned char build_actionlist[15198] = {
|
||||
254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,141,
|
||||
76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,137,68,36,
|
||||
20,252,247,198,237,15,132,244,13,248,14,252,247,198,237,15,132,244,10,199,
|
||||
@ -730,21 +730,22 @@ static const unsigned char build_actionlist[15177] = {
|
||||
255,141,180,253,134,233,139,1,137,105,252,252,137,65,252,248,255,139,139,
|
||||
233,139,4,129,139,128,233,139,108,36,48,137,147,233,137,171,233,252,255,224,
|
||||
255,141,180,253,134,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16,
|
||||
252,255,36,171,255,139,190,233,139,108,36,48,141,12,202,59,141,233,15,135,
|
||||
244,23,15,182,142,233,57,200,15,134,244,249,248,2,255,15,183,70,252,254,252,
|
||||
233,245,255,248,3,199,68,194,252,252,237,131,192,1,57,200,15,134,244,3,252,
|
||||
233,244,2,255,141,44,197,237,141,4,194,139,122,252,248,137,104,252,252,137,
|
||||
120,252,248,139,108,36,48,141,12,200,59,141,233,15,135,244,22,137,209,137,
|
||||
194,15,182,174,233,133,252,237,15,132,244,248,248,1,131,193,8,57,209,15,131,
|
||||
244,249,139,121,252,248,137,56,139,121,252,252,137,120,4,131,192,8,199,65,
|
||||
252,252,237,131,252,237,1,15,133,244,1,248,2,255,139,190,233,139,6,15,182,
|
||||
204,15,182,232,131,198,4,193,232,16,252,255,36,171,255,248,3,199,64,4,237,
|
||||
131,192,8,131,252,237,1,15,133,244,3,252,233,244,2,255,139,106,252,248,139,
|
||||
189,233,139,108,36,48,141,68,194,252,248,137,149,233,141,136,233,59,141,233,
|
||||
137,133,233,255,137,44,36,255,137,124,36,4,137,44,36,255,15,135,244,21,199,
|
||||
131,233,237,255,252,255,215,255,252,255,147,233,255,199,131,233,237,139,149,
|
||||
233,141,12,194,252,247,217,3,141,233,139,114,252,252,252,233,244,12,255,254,
|
||||
0
|
||||
252,255,36,171,255,137,252,245,209,252,237,129,229,239,102,131,172,253,43,
|
||||
233,1,15,132,244,142,255,139,190,233,139,108,36,48,141,12,202,59,141,233,
|
||||
15,135,244,23,15,182,142,233,57,200,15,134,244,249,248,2,255,15,183,70,252,
|
||||
254,252,233,245,255,248,3,199,68,194,252,252,237,131,192,1,57,200,15,134,
|
||||
244,3,252,233,244,2,255,141,44,197,237,141,4,194,139,122,252,248,137,104,
|
||||
252,252,137,120,252,248,139,108,36,48,141,12,200,59,141,233,15,135,244,22,
|
||||
137,209,137,194,15,182,174,233,133,252,237,15,132,244,248,248,1,131,193,8,
|
||||
57,209,15,131,244,249,139,121,252,248,137,56,139,121,252,252,137,120,4,131,
|
||||
192,8,199,65,252,252,237,131,252,237,1,15,133,244,1,248,2,255,139,190,233,
|
||||
139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,255,248,3,
|
||||
199,64,4,237,131,192,8,131,252,237,1,15,133,244,3,252,233,244,2,255,139,106,
|
||||
252,248,139,189,233,139,108,36,48,141,68,194,252,248,137,149,233,141,136,
|
||||
233,59,141,233,137,133,233,255,137,44,36,255,137,124,36,4,137,44,36,255,15,
|
||||
135,244,21,199,131,233,237,255,252,255,215,255,252,255,147,233,255,199,131,
|
||||
233,237,139,149,233,141,12,194,252,247,217,3,141,233,139,114,252,252,252,
|
||||
233,244,12,255,254,0
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -2278,6 +2279,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
|
||||
case BC_FUNCF:
|
||||
#if LJ_HASJIT
|
||||
dasm_put(Dst, 14895, HOTCOUNT_PCMASK, GG_DISP2HOT);
|
||||
#endif
|
||||
case BC_FUNCV: /* NYI: compiled vararg functions. */
|
||||
break;
|
||||
@ -2287,13 +2289,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
break;
|
||||
#endif
|
||||
case BC_IFUNCF:
|
||||
dasm_put(Dst, 14895, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
|
||||
dasm_put(Dst, 14916, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
|
||||
if (op == BC_JFUNCF) {
|
||||
dasm_put(Dst, 14925, BC_JLOOP);
|
||||
dasm_put(Dst, 14946, BC_JLOOP);
|
||||
} else {
|
||||
dasm_put(Dst, 10814);
|
||||
}
|
||||
dasm_put(Dst, 14934, LJ_TNIL);
|
||||
dasm_put(Dst, 14955, LJ_TNIL);
|
||||
break;
|
||||
|
||||
case BC_JFUNCV:
|
||||
@ -2304,30 +2306,30 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse)
|
||||
break; /* NYI: compiled vararg functions. */
|
||||
|
||||
case BC_IFUNCV:
|
||||
dasm_put(Dst, 14956, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
|
||||
dasm_put(Dst, 14977, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
|
||||
if (op == BC_JFUNCV) {
|
||||
dasm_put(Dst, 14925, BC_JLOOP);
|
||||
dasm_put(Dst, 14946, BC_JLOOP);
|
||||
} else {
|
||||
dasm_put(Dst, 15047, -4+PC2PROTO(k));
|
||||
dasm_put(Dst, 15068, -4+PC2PROTO(k));
|
||||
}
|
||||
dasm_put(Dst, 15069, LJ_TNIL);
|
||||
dasm_put(Dst, 15090, LJ_TNIL);
|
||||
break;
|
||||
|
||||
case BC_FUNCC:
|
||||
case BC_FUNCCW:
|
||||
dasm_put(Dst, 15091, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 15120);
|
||||
} else {
|
||||
dasm_put(Dst, 15124);
|
||||
}
|
||||
dasm_put(Dst, 15132, DISPATCH_GL(vmstate), ~LJ_VMST_C);
|
||||
dasm_put(Dst, 15112, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 15141);
|
||||
} else {
|
||||
dasm_put(Dst, 15145, DISPATCH_GL(wrapf));
|
||||
dasm_put(Dst, 15145);
|
||||
}
|
||||
dasm_put(Dst, 15150, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
|
||||
dasm_put(Dst, 15153, DISPATCH_GL(vmstate), ~LJ_VMST_C);
|
||||
if (op == BC_FUNCC) {
|
||||
dasm_put(Dst, 15162);
|
||||
} else {
|
||||
dasm_put(Dst, 15166, DISPATCH_GL(wrapf));
|
||||
}
|
||||
dasm_put(Dst, 15171, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
|
||||
break;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -2355,7 +2357,7 @@ static int build_backend(BuildCtx *ctx)
|
||||
|
||||
build_subroutines(ctx, cmov, sse);
|
||||
|
||||
dasm_put(Dst, 15175);
|
||||
dasm_put(Dst, 15196);
|
||||
for (op = 0; op < BC__MAX; op++)
|
||||
build_ins(ctx, (BCOp)op, op, cmov, sse);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user