aboutsummaryrefslogtreecommitdiff
path: root/src/lj_ir.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lj_ir.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/lj_ir.c b/src/lj_ir.c
index 1dd25f23..600e432c 100644
--- a/src/lj_ir.c
+++ b/src/lj_ir.c
@@ -38,7 +38,7 @@
38#define fins (&J->fold.ins) 38#define fins (&J->fold.ins)
39 39
40/* Pass IR on to next optimization in chain (FOLD). */ 40/* Pass IR on to next optimization in chain (FOLD). */
41#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J)) 41#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
42 42
43/* -- IR tables ----------------------------------------------------------- */ 43/* -- IR tables ----------------------------------------------------------- */
44 44
@@ -90,8 +90,9 @@ static void lj_ir_growbot(jit_State *J)
90{ 90{
91 IRIns *baseir = J->irbuf + J->irbotlim; 91 IRIns *baseir = J->irbuf + J->irbotlim;
92 MSize szins = J->irtoplim - J->irbotlim; 92 MSize szins = J->irtoplim - J->irbotlim;
93 lua_assert(szins != 0); 93 lj_assertJ(szins != 0, "zero IR size");
94 lua_assert(J->cur.nk == J->irbotlim || J->cur.nk-1 == J->irbotlim); 94 lj_assertJ(J->cur.nk == J->irbotlim || J->cur.nk-1 == J->irbotlim,
95 "unexpected IR growth");
95 if (J->cur.nins + (szins >> 1) < J->irtoplim) { 96 if (J->cur.nins + (szins >> 1) < J->irtoplim) {
96 /* More than half of the buffer is free on top: shift up by a quarter. */ 97 /* More than half of the buffer is free on top: shift up by a quarter. */
97 MSize ofs = szins >> 2; 98 MSize ofs = szins >> 2;
@@ -148,9 +149,10 @@ TRef lj_ir_call(jit_State *J, IRCallID id, ...)
148/* Load field of type t from GG_State + offset. Must be 32 bit aligned. */ 149/* Load field of type t from GG_State + offset. Must be 32 bit aligned. */
149LJ_FUNC TRef lj_ir_ggfload(jit_State *J, IRType t, uintptr_t ofs) 150LJ_FUNC TRef lj_ir_ggfload(jit_State *J, IRType t, uintptr_t ofs)
150{ 151{
151 lua_assert((ofs & 3) == 0); 152 lj_assertJ((ofs & 3) == 0, "unaligned GG_State field offset");
152 ofs >>= 2; 153 ofs >>= 2;
153 lua_assert(ofs >= IRFL__MAX && ofs <= 0x3ff); /* 10 bit FOLD key limit. */ 154 lj_assertJ(ofs >= IRFL__MAX && ofs <= 0x3ff,
155 "GG_State field offset breaks 10 bit FOLD key limit");
154 lj_ir_set(J, IRT(IR_FLOAD, t), REF_NIL, ofs); 156 lj_ir_set(J, IRT(IR_FLOAD, t), REF_NIL, ofs);
155 return lj_opt_fold(J); 157 return lj_opt_fold(J);
156} 158}
@@ -181,7 +183,7 @@ static LJ_AINLINE IRRef ir_nextk(jit_State *J)
181static LJ_AINLINE IRRef ir_nextk64(jit_State *J) 183static LJ_AINLINE IRRef ir_nextk64(jit_State *J)
182{ 184{
183 IRRef ref = J->cur.nk - 2; 185 IRRef ref = J->cur.nk - 2;
184 lua_assert(J->state != LJ_TRACE_ASM); 186 lj_assertJ(J->state != LJ_TRACE_ASM, "bad JIT state");
185 if (LJ_UNLIKELY(ref < J->irbotlim)) lj_ir_growbot(J); 187 if (LJ_UNLIKELY(ref < J->irbotlim)) lj_ir_growbot(J);
186 J->cur.nk = ref; 188 J->cur.nk = ref;
187 return ref; 189 return ref;
@@ -277,7 +279,7 @@ TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t)
277{ 279{
278 IRIns *ir, *cir = J->cur.ir; 280 IRIns *ir, *cir = J->cur.ir;
279 IRRef ref; 281 IRRef ref;
280 lua_assert(!isdead(J2G(J), o)); 282 lj_assertJ(!isdead(J2G(J), o), "interning of dead GC object");
281 for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev) 283 for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev)
282 if (ir_kgc(&cir[ref]) == o) 284 if (ir_kgc(&cir[ref]) == o)
283 goto found; 285 goto found;
@@ -299,7 +301,7 @@ TRef lj_ir_ktrace(jit_State *J)
299{ 301{
300 IRRef ref = ir_nextkgc(J); 302 IRRef ref = ir_nextkgc(J);
301 IRIns *ir = IR(ref); 303 IRIns *ir = IR(ref);
302 lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE); 304 lj_assertJ(irt_toitype_(IRT_P64) == LJ_TTRACE, "mismatched type mapping");
303 ir->t.irt = IRT_P64; 305 ir->t.irt = IRT_P64;
304 ir->o = LJ_GC64 ? IR_KNUM : IR_KNULL; /* Not IR_KGC yet, but same size. */ 306 ir->o = LJ_GC64 ? IR_KNUM : IR_KNULL; /* Not IR_KGC yet, but same size. */
305 ir->op12 = 0; 307 ir->op12 = 0;
@@ -313,7 +315,7 @@ TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr)
313 IRIns *ir, *cir = J->cur.ir; 315 IRIns *ir, *cir = J->cur.ir;
314 IRRef ref; 316 IRRef ref;
315#if LJ_64 && !LJ_GC64 317#if LJ_64 && !LJ_GC64
316 lua_assert((void *)(uintptr_t)u32ptr(ptr) == ptr); 318 lj_assertJ((void *)(uintptr_t)u32ptr(ptr) == ptr, "out-of-range GC pointer");
317#endif 319#endif
318 for (ref = J->chain[op]; ref; ref = cir[ref].prev) 320 for (ref = J->chain[op]; ref; ref = cir[ref].prev)
319 if (ir_kptr(&cir[ref]) == ptr) 321 if (ir_kptr(&cir[ref]) == ptr)
@@ -360,7 +362,8 @@ TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot)
360 IRRef2 op12 = IRREF2((IRRef1)key, (IRRef1)slot); 362 IRRef2 op12 = IRREF2((IRRef1)key, (IRRef1)slot);
361 IRRef ref; 363 IRRef ref;
362 /* Const part is not touched by CSE/DCE, so 0-65535 is ok for IRMlit here. */ 364 /* Const part is not touched by CSE/DCE, so 0-65535 is ok for IRMlit here. */
363 lua_assert(tref_isk(key) && slot == (IRRef)(IRRef1)slot); 365 lj_assertJ(tref_isk(key) && slot == (IRRef)(IRRef1)slot,
366 "out-of-range key/slot");
364 for (ref = J->chain[IR_KSLOT]; ref; ref = cir[ref].prev) 367 for (ref = J->chain[IR_KSLOT]; ref; ref = cir[ref].prev)
365 if (cir[ref].op12 == op12) 368 if (cir[ref].op12 == op12)
366 goto found; 369 goto found;
@@ -381,7 +384,7 @@ found:
381void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir) 384void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)
382{ 385{
383 UNUSED(L); 386 UNUSED(L);
384 lua_assert(ir->o != IR_KSLOT); /* Common mistake. */ 387 lj_assertL(ir->o != IR_KSLOT, "unexpected KSLOT"); /* Common mistake. */
385 switch (ir->o) { 388 switch (ir->o) {
386 case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break; 389 case IR_KPRI: setpriV(tv, irt_toitype(ir->t)); break;
387 case IR_KINT: setintV(tv, ir->i); break; 390 case IR_KINT: setintV(tv, ir->i); break;
@@ -397,7 +400,7 @@ void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)
397 break; 400 break;
398 } 401 }
399#endif 402#endif
400 default: lua_assert(0); break; 403 default: lj_assertL(0, "bad IR constant op %d", ir->o); break;
401 } 404 }
402} 405}
403 406
@@ -457,7 +460,7 @@ int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op)
457 case IR_UGE: return !(a < b); 460 case IR_UGE: return !(a < b);
458 case IR_ULE: return !(a > b); 461 case IR_ULE: return !(a > b);
459 case IR_UGT: return !(a <= b); 462 case IR_UGT: return !(a <= b);
460 default: lua_assert(0); return 0; 463 default: lj_assertX(0, "bad IR op %d", op); return 0;
461 } 464 }
462} 465}
463 466
@@ -470,7 +473,7 @@ int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op)
470 case IR_GE: return (res >= 0); 473 case IR_GE: return (res >= 0);
471 case IR_LE: return (res <= 0); 474 case IR_LE: return (res <= 0);
472 case IR_GT: return (res > 0); 475 case IR_GT: return (res > 0);
473 default: lua_assert(0); return 0; 476 default: lj_assertX(0, "bad IR op %d", op); return 0;
474 } 477 }
475} 478}
476 479