aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-01-17 01:20:10 +0100
committerMike Pall <mike>2011-01-17 01:20:10 +0100
commit66ba1e68aab23fa09fcbe84b79d4992c92440b0c (patch)
tree6803a405c9a478edac3346cd8eb762b26a6dd314 /src
parentb2ff889c6e2bd637a906b7b81641faf5682f771e (diff)
downloadluajit-66ba1e68aab23fa09fcbe84b79d4992c92440b0c.tar.gz
luajit-66ba1e68aab23fa09fcbe84b79d4992c92440b0c.tar.bz2
luajit-66ba1e68aab23fa09fcbe84b79d4992c92440b0c.zip
Add trace recorder infrastructure for instruction post-processing.
Diffstat (limited to 'src')
-rw-r--r--src/lj_jit.h10
-rw-r--r--src/lj_record.c20
-rw-r--r--src/lj_trace.c3
3 files changed, 32 insertions, 1 deletions
diff --git a/src/lj_jit.h b/src/lj_jit.h
index 6c930034..55d6d0df 100644
--- a/src/lj_jit.h
+++ b/src/lj_jit.h
@@ -104,9 +104,15 @@ typedef enum {
104 LJ_TRACE_START, /* New trace started. */ 104 LJ_TRACE_START, /* New trace started. */
105 LJ_TRACE_END, /* End of trace. */ 105 LJ_TRACE_END, /* End of trace. */
106 LJ_TRACE_ASM, /* Assemble trace. */ 106 LJ_TRACE_ASM, /* Assemble trace. */
107 LJ_TRACE_ERR, /* Trace aborted with error. */ 107 LJ_TRACE_ERR /* Trace aborted with error. */
108} TraceState; 108} TraceState;
109 109
110/* Post-processing action. */
111typedef enum {
112 LJ_POST_NONE, /* No action. */
113 LJ_POST_FIXGUARD /* Fixup and emit pending guard. */
114} PostProc;
115
110/* Machine code type. */ 116/* Machine code type. */
111typedef uint8_t MCode; 117typedef uint8_t MCode;
112 118
@@ -284,6 +290,8 @@ typedef struct jit_State {
284 SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */ 290 SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */
285 MSize sizesnapmap; /* Size of temp. snapshot map buffer. */ 291 MSize sizesnapmap; /* Size of temp. snapshot map buffer. */
286 292
293 PostProc postproc; /* Required post-processing after execution. */
294
287 GCRef *trace; /* Array of traces. */ 295 GCRef *trace; /* Array of traces. */
288 TraceNo freetrace; /* Start of scan for next free trace. */ 296 TraceNo freetrace; /* Start of scan for next free trace. */
289 MSize sizetrace; /* Size of trace array. */ 297 MSize sizetrace; /* Size of trace array. */
diff --git a/src/lj_record.c b/src/lj_record.c
index dc3f3df0..1669fde1 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1365,6 +1365,26 @@ void lj_record_ins(jit_State *J)
1365 BCOp op; 1365 BCOp op;
1366 TRef ra, rb, rc; 1366 TRef ra, rb, rc;
1367 1367
1368 /* Perform post-processing action before recording the next instruction. */
1369 if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) {
1370 switch (J->postproc) {
1371 case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */
1372 if (!tvistruecond(&J2G(J)->tmptv2)) {
1373 BCReg s;
1374 J->fold.ins.o ^= 1; /* Flip guard to opposite. */
1375 for (s = 0; s < J->maxslot; s++) /* Fixup stack slot (if any). */
1376 if (J->base[s] == TREF_TRUE && tvisfalse(&J->L->base[s])) {
1377 J->base[s] = TREF_FALSE;
1378 break;
1379 }
1380 }
1381 lj_opt_fold(J); /* Emit pending guard. */
1382 break;
1383 default: lua_assert(0); break;
1384 }
1385 J->postproc = LJ_POST_NONE;
1386 }
1387
1368 /* Need snapshot before recording next bytecode (e.g. after a store). */ 1388 /* Need snapshot before recording next bytecode (e.g. after a store). */
1369 if (J->needsnap) { 1389 if (J->needsnap) {
1370 J->needsnap = 0; 1390 J->needsnap = 0;
diff --git a/src/lj_trace.c b/src/lj_trace.c
index c508c02a..421278e1 100644
--- a/src/lj_trace.c
+++ b/src/lj_trace.c
@@ -388,6 +388,7 @@ static void trace_start(jit_State *J)
388 J->needsnap = 0; 388 J->needsnap = 0;
389 J->bcskip = 0; 389 J->bcskip = 0;
390 J->guardemit.irt = 0; 390 J->guardemit.irt = 0;
391 J->postproc = LJ_POST_NONE;
391 setgcref(J->cur.startpt, obj2gco(J->pt)); 392 setgcref(J->cur.startpt, obj2gco(J->pt));
392 393
393 L = J->L; 394 L = J->L;
@@ -454,6 +455,7 @@ static void trace_stop(jit_State *J)
454 455
455 /* Commit new mcode only after all patching is done. */ 456 /* Commit new mcode only after all patching is done. */
456 lj_mcode_commit(J, J->cur.mcode); 457 lj_mcode_commit(J, J->cur.mcode);
458 J->postproc = LJ_POST_NONE;
457 trace_save(J); 459 trace_save(J);
458 460
459 L = J->L; 461 L = J->L;
@@ -485,6 +487,7 @@ static int trace_abort(jit_State *J)
485 TraceError e = LJ_TRERR_RECERR; 487 TraceError e = LJ_TRERR_RECERR;
486 TraceNo traceno; 488 TraceNo traceno;
487 489
490 J->postproc = LJ_POST_NONE;
488 lj_mcode_abort(J); 491 lj_mcode_abort(J);
489 if (tvisnum(L->top-1)) 492 if (tvisnum(L->top-1))
490 e = (TraceError)lj_num2int(numV(L->top-1)); 493 e = (TraceError)lj_num2int(numV(L->top-1));