summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2013-03-23 14:51:23 +0100
committerMike Pall <mike>2013-03-23 14:51:23 +0100
commit172bd953657904e1b133b99ec328271c4e69c52c (patch)
treebf23e253a5d1b50cd95a88721d9da8a5f4bba65e
parentd147eedac963f6dfc757d269c180985fd9c0c1e7 (diff)
downloadluajit-172bd953657904e1b133b99ec328271c4e69c52c.tar.gz
luajit-172bd953657904e1b133b99ec328271c4e69c52c.tar.bz2
luajit-172bd953657904e1b133b99ec328271c4e69c52c.zip
FFI: Fix snapshot substitution in SPLIT pass.
-rw-r--r--src/lj_opt_split.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/lj_opt_split.c b/src/lj_opt_split.c
index 303af03c..5a8c33b9 100644
--- a/src/lj_opt_split.c
+++ b/src/lj_opt_split.c
@@ -195,6 +195,19 @@ static IRRef split_ptr(jit_State *J, IRIns *oir, IRRef ref)
195 return split_emit(J, IRTI(IR_ADD), nref, lj_ir_kint(J, ofs)); 195 return split_emit(J, IRTI(IR_ADD), nref, lj_ir_kint(J, ofs));
196} 196}
197 197
198/* Substitute references of a snapshot. */
199static void split_subst_snap(jit_State *J, SnapShot *snap, IRIns *oir)
200{
201 SnapEntry *map = &J->cur.snapmap[snap->mapofs];
202 MSize n, nent = snap->nent;
203 for (n = 0; n < nent; n++) {
204 SnapEntry sn = map[n];
205 IRIns *ir = &oir[snap_ref(sn)];
206 if (!(LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && irref_isk(snap_ref(sn))))
207 map[n] = ((sn & 0xffff0000) | ir->prev);
208 }
209}
210
198/* Transform the old IR to the new IR. */ 211/* Transform the old IR to the new IR. */
199static void split_ir(jit_State *J) 212static void split_ir(jit_State *J)
200{ 213{
@@ -203,7 +216,8 @@ static void split_ir(jit_State *J)
203 MSize need = (irlen+1)*(sizeof(IRIns) + sizeof(IRRef1)); 216 MSize need = (irlen+1)*(sizeof(IRIns) + sizeof(IRRef1));
204 IRIns *oir = (IRIns *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, need); 217 IRIns *oir = (IRIns *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, need);
205 IRRef1 *hisubst; 218 IRRef1 *hisubst;
206 IRRef ref; 219 IRRef ref, snref;
220 SnapShot *snap;
207 221
208 /* Copy old IR to buffer. */ 222 /* Copy old IR to buffer. */
209 memcpy(oir, IR(nk), irlen*sizeof(IRIns)); 223 memcpy(oir, IR(nk), irlen*sizeof(IRIns));
@@ -230,12 +244,20 @@ static void split_ir(jit_State *J)
230 } 244 }
231 245
232 /* Process old IR instructions. */ 246 /* Process old IR instructions. */
247 snap = J->cur.snap;
248 snref = snap->ref;
233 for (ref = REF_FIRST; ref < nins; ref++) { 249 for (ref = REF_FIRST; ref < nins; ref++) {
234 IRIns *ir = &oir[ref]; 250 IRIns *ir = &oir[ref];
235 IRRef nref = lj_ir_nextins(J); 251 IRRef nref = lj_ir_nextins(J);
236 IRIns *nir = IR(nref); 252 IRIns *nir = IR(nref);
237 IRRef hi = 0; 253 IRRef hi = 0;
238 254
255 if (ref >= snref) {
256 snap->ref = nref;
257 split_subst_snap(J, snap++, oir);
258 snref = snap < &J->cur.snap[J->cur.nsnap] ? snap->ref : ~(IRRef)0;
259 }
260
239 /* Copy-substitute old instruction to new instruction. */ 261 /* Copy-substitute old instruction to new instruction. */
240 nir->op1 = ir->op1 < nk ? ir->op1 : oir[ir->op1].prev; 262 nir->op1 = ir->op1 < nk ? ir->op1 : oir[ir->op1].prev;
241 nir->op2 = ir->op2 < nk ? ir->op2 : oir[ir->op2].prev; 263 nir->op2 = ir->op2 < nk ? ir->op2 : oir[ir->op2].prev;
@@ -635,6 +657,10 @@ static void split_ir(jit_State *J)
635 } 657 }
636 hisubst[ref] = hi; /* Store hiword substitution. */ 658 hisubst[ref] = hi; /* Store hiword substitution. */
637 } 659 }
660 if (snref == nins) { /* Substitution for last snapshot. */
661 snap->ref = J->cur.nins;
662 split_subst_snap(J, snap, oir);
663 }
638 664
639 /* Add PHI marks. */ 665 /* Add PHI marks. */
640 for (ref = J->cur.nins-1; ref >= REF_FIRST; ref--) { 666 for (ref = J->cur.nins-1; ref >= REF_FIRST; ref--) {
@@ -643,24 +669,6 @@ static void split_ir(jit_State *J)
643 if (!irref_isk(ir->op1)) irt_setphi(IR(ir->op1)->t); 669 if (!irref_isk(ir->op1)) irt_setphi(IR(ir->op1)->t);
644 if (ir->op2 > J->loopref) irt_setphi(IR(ir->op2)->t); 670 if (ir->op2 > J->loopref) irt_setphi(IR(ir->op2)->t);
645 } 671 }
646
647 /* Substitute snapshot maps. */
648 oir[nins].prev = J->cur.nins; /* Substitution for last snapshot. */
649 {
650 SnapNo i, nsnap = J->cur.nsnap;
651 for (i = 0; i < nsnap; i++) {
652 SnapShot *snap = &J->cur.snap[i];
653 SnapEntry *map = &J->cur.snapmap[snap->mapofs];
654 MSize n, nent = snap->nent;
655 snap->ref = snap->ref == REF_FIRST ? REF_FIRST : oir[snap->ref].prev;
656 for (n = 0; n < nent; n++) {
657 SnapEntry sn = map[n];
658 IRIns *ir = &oir[snap_ref(sn)];
659 if (!(LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && irref_isk(snap_ref(sn))))
660 map[n] = ((sn & 0xffff0000) | ir->prev);
661 }
662 }
663 }
664} 672}
665 673
666/* Protected callback for split pass. */ 674/* Protected callback for split pass. */