]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Simplify GCtrace * reference embedding for trace stitching.
authorMike Pall <mike>
Sun, 22 May 2016 21:40:37 +0000 (23:40 +0200)
committerMike Pall <mike>
Sun, 22 May 2016 21:40:37 +0000 (23:40 +0200)
This is now possible due to the immovable IR.
Contributed by Peter Cawley.

src/lj_asm.c
src/lj_ffrecord.c
src/lj_ir.c
src/lj_iropt.h
src/lj_jit.h
src/lj_trace.c

index 5235dd006c866fdafd799a19eafe4fb429946438..9b394beba6fbbb7bdf1fb59698f0c219fb971116 100644 (file)
@@ -1933,6 +1933,11 @@ static void asm_tail_link(ASMState *as)
   }
   emit_addptr(as, RID_BASE, 8*(int32_t)baseslot);
 
+  if (as->J->ktrace) {  /* Patch ktrace slot with the final GCtrace pointer. */
+    setgcref(IR(as->J->ktrace)->gcr, obj2gco(as->J->curfinal));
+    IR(as->J->ktrace)->o = IR_KGC;
+  }
+
   /* Sync the interpreter state with the on-trace state. */
   asm_stack_restore(as, snap);
 
index 14fde4d9ecbc5d8a4a81fda4c1a384bd12c6d153..ae5676220083ba244f01de621c3eef3e1b04569a 100644 (file)
@@ -118,9 +118,8 @@ static void recff_stitch(jit_State *J)
   /* Ditto for the IR. */
   memmove(&J->base[1], &J->base[-1], sizeof(TRef)*(J->maxslot+1));
   J->base[0] = lj_ir_kptr(J, contptr(cont)) | TREF_CONT;
-  J->ktracep = lj_ir_k64_reserve(J);
-  lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE);
-  J->base[-1] = emitir(IRT(IR_XLOAD, IRT_P64), lj_ir_kptr(J, &J->ktracep->gcr), 0);
+  J->base[-1] = lj_ir_ktrace(J);
+  J->ktrace = tref_ref(J->base[-1]);
   J->base += 2;
   J->baseslot += 2;
   J->framedepth++;
index 593b4127a1549b411b1b8ee1686d0d26a2528d5f..acb394638838278e3181dcc3a7e8ba9b0f384bf4 100644 (file)
@@ -348,6 +348,18 @@ found:
   return TREF(ref, t);
 }
 
+/* Allocate GCtrace constant placeholder (no interning). */
+TRef lj_ir_ktrace(jit_State *J)
+{
+  IRRef ref = ir_nextk(J);
+  IRIns *ir = IR(ref);
+  lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE);
+  ir->t.irt = IRT_P64;
+  ir->o = IR_KNULL;  /* Not IR_KGC yet, but same size. */
+  ir->prev = 0;
+  return TREF(ref, IRT_P64);
+}
+
 /* Intern 32 bit pointer constant. */
 TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr)
 {
index 4693367187805a8cb7913ebf87e70d662967f15c..fdc5f0d26efae6f34f01f66fb7ed6820903f5ffd 100644 (file)
@@ -51,6 +51,7 @@ LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t);
 LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr);
 LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t);
 LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot);
+LJ_FUNC TRef lj_ir_ktrace(jit_State *J);
 
 #if LJ_64
 #define lj_ir_kintp(J, k)      lj_ir_kint64(J, (uint64_t)(k))
index ad9d62aff091c2f155b6e10fd6e48a731100514a..eafbc327c7dde70634898a7f22ae1e77bd40c293 100644 (file)
@@ -416,7 +416,7 @@ typedef struct jit_State {
   GCRef *trace;                /* Array of traces. */
   TraceNo freetrace;   /* Start of scan for next free trace. */
   MSize sizetrace;     /* Size of trace array. */
-  TValue *ktracep;     /* Pointer to K64Array slot with GCtrace pointer. */
+  IRRef1 ktrace;       /* Reference to KGC with GCtrace. */
 
   IRRef1 chain[IR__MAX];  /* IR instruction skip-list chain anchors. */
   TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA];  /* Stack slot map. */
index 19ddba41603ddf9b435716105b3bd7c51526a3e9..eaf9365c14ea69c98253223eaad72d16b9ad6b82 100644 (file)
@@ -436,7 +436,7 @@ static void trace_start(jit_State *J)
   J->postproc = LJ_POST_NONE;
   lj_resetsplit(J);
   J->retryrec = 0;
-  J->ktracep = NULL;
+  J->ktrace = 0;
   setgcref(J->cur.startpt, obj2gco(J->pt));
 
   L = J->L;
@@ -512,9 +512,6 @@ static void trace_stop(jit_State *J)
   lj_mcode_commit(J, J->cur.mcode);
   J->postproc = LJ_POST_NONE;
   trace_save(J, T);
-  if (J->ktracep) {  /* Patch K64Array slot with the final GCtrace pointer. */
-    setgcV(J->L, J->ktracep, obj2gco(T), LJ_TTRACE);
-  }
 
   L = J->L;
   lj_vmevent_send(L, TRACE,