diff options
Diffstat (limited to 'src/lj_record.c')
-rw-r--r-- | src/lj_record.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/lj_record.c b/src/lj_record.c index 63d5e4c1..49d743a2 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -212,9 +212,10 @@ static void canonicalize_slots(jit_State *J) | |||
212 | } | 212 | } |
213 | 213 | ||
214 | /* Stop recording. */ | 214 | /* Stop recording. */ |
215 | static void rec_stop(jit_State *J, TraceNo lnk) | 215 | static void rec_stop(jit_State *J, TraceLink linktype, TraceNo lnk) |
216 | { | 216 | { |
217 | lj_trace_end(J); | 217 | lj_trace_end(J); |
218 | J->cur.linktype = (uint8_t)linktype; | ||
218 | J->cur.link = (uint16_t)lnk; | 219 | J->cur.link = (uint16_t)lnk; |
219 | /* Looping back at the same stack level? */ | 220 | /* Looping back at the same stack level? */ |
220 | if (lnk == J->cur.traceno && J->framedepth + J->retdepth == 0) { | 221 | if (lnk == J->cur.traceno && J->framedepth + J->retdepth == 0) { |
@@ -522,7 +523,7 @@ static void rec_loop_interp(jit_State *J, const BCIns *pc, LoopEvent ev) | |||
522 | /* Same loop? */ | 523 | /* Same loop? */ |
523 | if (ev == LOOPEV_LEAVE) /* Must loop back to form a root trace. */ | 524 | if (ev == LOOPEV_LEAVE) /* Must loop back to form a root trace. */ |
524 | lj_trace_err(J, LJ_TRERR_LLEAVE); | 525 | lj_trace_err(J, LJ_TRERR_LLEAVE); |
525 | rec_stop(J, J->cur.traceno); /* Root trace forms a loop. */ | 526 | rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Looping root trace. */ |
526 | } else if (ev != LOOPEV_LEAVE) { /* Entering inner loop? */ | 527 | } else if (ev != LOOPEV_LEAVE) { /* Entering inner loop? */ |
527 | /* It's usually better to abort here and wait until the inner loop | 528 | /* It's usually better to abort here and wait until the inner loop |
528 | ** is traced. But if the inner loop repeatedly didn't loop back, | 529 | ** is traced. But if the inner loop repeatedly didn't loop back, |
@@ -553,8 +554,9 @@ static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev) | |||
553 | } else if (ev != LOOPEV_LEAVE) { /* Side trace enters a compiled loop. */ | 554 | } else if (ev != LOOPEV_LEAVE) { /* Side trace enters a compiled loop. */ |
554 | J->instunroll = 0; /* Cannot continue across a compiled loop op. */ | 555 | J->instunroll = 0; /* Cannot continue across a compiled loop op. */ |
555 | if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) | 556 | if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) |
556 | lnk = J->cur.traceno; /* Can form an extra loop. */ | 557 | rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Form an extra loop. */ |
557 | rec_stop(J, lnk); /* Link to the loop. */ | 558 | else |
559 | rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the loop. */ | ||
558 | } /* Side trace continues across a loop that's left or not entered. */ | 560 | } /* Side trace continues across a loop that's left or not entered. */ |
559 | } | 561 | } |
560 | 562 | ||
@@ -678,7 +680,7 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) | |||
678 | if (check_downrec_unroll(J, pt)) { | 680 | if (check_downrec_unroll(J, pt)) { |
679 | J->maxslot = (BCReg)(rbase + gotresults); | 681 | J->maxslot = (BCReg)(rbase + gotresults); |
680 | lj_snap_purge(J); | 682 | lj_snap_purge(J); |
681 | rec_stop(J, J->cur.traceno); /* Down-recursion. */ | 683 | rec_stop(J, LJ_TRLINK_DOWNREC, J->cur.traceno); /* Down-recursion. */ |
682 | return; | 684 | return; |
683 | } | 685 | } |
684 | lj_snap_add(J); | 686 | lj_snap_add(J); |
@@ -1292,7 +1294,10 @@ static void check_call_unroll(jit_State *J) | |||
1292 | if (J->pc == J->startpc) { | 1294 | if (J->pc == J->startpc) { |
1293 | if (count + J->tailcalled > J->param[JIT_P_recunroll]) { | 1295 | if (count + J->tailcalled > J->param[JIT_P_recunroll]) { |
1294 | J->pc++; | 1296 | J->pc++; |
1295 | rec_stop(J, J->cur.traceno); /* Up-recursion or tail-recursion. */ | 1297 | if (J->framedepth + J->retdepth == 0) |
1298 | rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Tail-recursion. */ | ||
1299 | else | ||
1300 | rec_stop(J, LJ_TRLINK_UPREC, J->cur.traceno); /* Up-recursion. */ | ||
1296 | } | 1301 | } |
1297 | } else { | 1302 | } else { |
1298 | if (count > J->param[JIT_P_callunroll]) | 1303 | if (count > J->param[JIT_P_callunroll]) |
@@ -1350,8 +1355,9 @@ static void rec_func_jit(jit_State *J, TraceNo lnk) | |||
1350 | rec_func_setup(J); | 1355 | rec_func_setup(J); |
1351 | J->instunroll = 0; /* Cannot continue across a compiled function. */ | 1356 | J->instunroll = 0; /* Cannot continue across a compiled function. */ |
1352 | if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) | 1357 | if (J->pc == J->startpc && J->framedepth + J->retdepth == 0) |
1353 | lnk = J->cur.traceno; /* Can form an extra tail-recursive loop. */ | 1358 | rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Extra tail-recursion. */ |
1354 | rec_stop(J, lnk); /* Link to the function. */ | 1359 | else |
1360 | rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the function. */ | ||
1355 | } | 1361 | } |
1356 | 1362 | ||
1357 | /* -- Vararg handling ----------------------------------------------------- */ | 1363 | /* -- Vararg handling ----------------------------------------------------- */ |
@@ -1863,7 +1869,7 @@ void lj_record_ins(jit_State *J) | |||
1863 | case BC_JFORI: | 1869 | case BC_JFORI: |
1864 | lua_assert(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL); | 1870 | lua_assert(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL); |
1865 | if (rec_for(J, pc, 0) != LOOPEV_LEAVE) /* Link to existing loop. */ | 1871 | if (rec_for(J, pc, 0) != LOOPEV_LEAVE) /* Link to existing loop. */ |
1866 | rec_stop(J, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J])); | 1872 | rec_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J])); |
1867 | /* Continue tracing if the loop is not entered. */ | 1873 | /* Continue tracing if the loop is not entered. */ |
1868 | break; | 1874 | break; |
1869 | 1875 | ||
@@ -2121,8 +2127,9 @@ void lj_record_setup(jit_State *J) | |||
2121 | sidecheck: | 2127 | sidecheck: |
2122 | if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] || | 2128 | if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] || |
2123 | T->snap[J->exitno].count >= J->param[JIT_P_hotexit] + | 2129 | T->snap[J->exitno].count >= J->param[JIT_P_hotexit] + |
2124 | J->param[JIT_P_tryside]) | 2130 | J->param[JIT_P_tryside]) { |
2125 | rec_stop(J, TRACE_INTERP); | 2131 | rec_stop(J, LJ_TRLINK_INTERP, 0); |
2132 | } | ||
2126 | } else { /* Root trace. */ | 2133 | } else { /* Root trace. */ |
2127 | J->cur.root = 0; | 2134 | J->cur.root = 0; |
2128 | J->cur.startins = *J->pc; | 2135 | J->cur.startins = *J->pc; |