diff options
author | Mike Pall <mike> | 2011-01-19 00:40:03 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-01-19 00:40:03 +0100 |
commit | 925050fe3ffae269f77757679270432dbad7f010 (patch) | |
tree | b332535f323ca99d7ee9d5b99c73f15de09ea43b /src | |
parent | 685dfc317270642fbf2a686799ca2b31ea42e0de (diff) | |
download | luajit-925050fe3ffae269f77757679270432dbad7f010.tar.gz luajit-925050fe3ffae269f77757679270432dbad7f010.tar.bz2 luajit-925050fe3ffae269f77757679270432dbad7f010.zip |
Differentiate between IR_KPTR and IR_KKPTR.
IR_KPTR holds a const pointer to possibly non-const content.
IR_KKPTR holds a const pointer to definitely const content.
Note that only content known by the VM to be const qualifies.
Content tagged as const by users (e.g. const char *) doesn't.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_asm.c | 6 | ||||
-rw-r--r-- | src/lj_ir.c | 14 | ||||
-rw-r--r-- | src/lj_ir.h | 4 | ||||
-rw-r--r-- | src/lj_iropt.h | 4 | ||||
-rw-r--r-- | src/lj_opt_fold.c | 21 | ||||
-rw-r--r-- | src/lj_record.c | 6 |
6 files changed, 32 insertions, 23 deletions
diff --git a/src/lj_asm.c b/src/lj_asm.c index db126d74..bda86fc4 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c | |||
@@ -636,7 +636,7 @@ static Reg ra_rematk(ASMState *as, IRIns *ir) | |||
636 | #endif | 636 | #endif |
637 | } else { | 637 | } else { |
638 | lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || | 638 | lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || |
639 | ir->o == IR_KPTR || ir->o == IR_KNULL); | 639 | ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL); |
640 | emit_loadi(as, r, ir->i); | 640 | emit_loadi(as, r, ir->i); |
641 | } | 641 | } |
642 | return r; | 642 | return r; |
@@ -946,7 +946,7 @@ static void ra_left(ASMState *as, Reg dest, IRRef lref) | |||
946 | #endif | 946 | #endif |
947 | } else { | 947 | } else { |
948 | lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || | 948 | lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || |
949 | ir->o == IR_KPTR || ir->o == IR_KNULL); | 949 | ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL); |
950 | emit_loadi(as, dest, ir->i); | 950 | emit_loadi(as, dest, ir->i); |
951 | return; | 951 | return; |
952 | } | 952 | } |
@@ -1312,7 +1312,7 @@ static void asm_fusexref(ASMState *as, IRRef ref, RegSet allow) | |||
1312 | { | 1312 | { |
1313 | IRIns *ir = IR(ref); | 1313 | IRIns *ir = IR(ref); |
1314 | as->mrm.idx = RID_NONE; | 1314 | as->mrm.idx = RID_NONE; |
1315 | if (ir->o == IR_KPTR) { | 1315 | if (ir->o == IR_KPTR || ir->o == IR_KKPTR) { |
1316 | as->mrm.ofs = ir->i; | 1316 | as->mrm.ofs = ir->i; |
1317 | as->mrm.base = RID_NONE; | 1317 | as->mrm.base = RID_NONE; |
1318 | } else if (ir->o == IR_STRREF) { | 1318 | } else if (ir->o == IR_STRREF) { |
diff --git a/src/lj_ir.c b/src/lj_ir.c index e81beb81..e1ce5839 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
@@ -311,21 +311,21 @@ found: | |||
311 | } | 311 | } |
312 | 312 | ||
313 | /* Intern 32 bit pointer constant. */ | 313 | /* Intern 32 bit pointer constant. */ |
314 | TRef lj_ir_kptr(jit_State *J, void *ptr) | 314 | TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr) |
315 | { | 315 | { |
316 | IRIns *ir, *cir = J->cur.ir; | 316 | IRIns *ir, *cir = J->cur.ir; |
317 | IRRef ref; | 317 | IRRef ref; |
318 | lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr); | 318 | lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr); |
319 | for (ref = J->chain[IR_KPTR]; ref; ref = cir[ref].prev) | 319 | for (ref = J->chain[op]; ref; ref = cir[ref].prev) |
320 | if (mref(cir[ref].ptr, void) == ptr) | 320 | if (mref(cir[ref].ptr, void) == ptr) |
321 | goto found; | 321 | goto found; |
322 | ref = ir_nextk(J); | 322 | ref = ir_nextk(J); |
323 | ir = IR(ref); | 323 | ir = IR(ref); |
324 | setmref(ir->ptr, ptr); | 324 | setmref(ir->ptr, ptr); |
325 | ir->t.irt = IRT_P32; | 325 | ir->t.irt = IRT_P32; |
326 | ir->o = IR_KPTR; | 326 | ir->o = op; |
327 | ir->prev = J->chain[IR_KPTR]; | 327 | ir->prev = J->chain[op]; |
328 | J->chain[IR_KPTR] = (IRRef1)ref; | 328 | J->chain[op] = (IRRef1)ref; |
329 | found: | 329 | found: |
330 | return TREF(ref, IRT_P32); | 330 | return TREF(ref, IRT_P32); |
331 | } | 331 | } |
@@ -382,7 +382,9 @@ void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir) | |||
382 | case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break; | 382 | case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break; |
383 | case IR_KINT: setintV(tv, ir->i); break; | 383 | case IR_KINT: setintV(tv, ir->i); break; |
384 | case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break; | 384 | case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break; |
385 | case IR_KPTR: case IR_KNULL: setlightudV(tv, mref(ir->ptr, void)); break; | 385 | case IR_KPTR: case IR_KKPTR: case IR_KNULL: |
386 | setlightudV(tv, mref(ir->ptr, void)); | ||
387 | break; | ||
386 | case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break; | 388 | case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break; |
387 | #if LJ_HASFFI | 389 | #if LJ_HASFFI |
388 | case IR_KINT64: { | 390 | case IR_KINT64: { |
diff --git a/src/lj_ir.h b/src/lj_ir.h index 11ecdf27..d3104017 100644 --- a/src/lj_ir.h +++ b/src/lj_ir.h | |||
@@ -42,6 +42,7 @@ | |||
42 | _(KINT, N , cst, ___) \ | 42 | _(KINT, N , cst, ___) \ |
43 | _(KGC, N , cst, ___) \ | 43 | _(KGC, N , cst, ___) \ |
44 | _(KPTR, N , cst, ___) \ | 44 | _(KPTR, N , cst, ___) \ |
45 | _(KKPTR, N , cst, ___) \ | ||
45 | _(KNULL, N , cst, ___) \ | 46 | _(KNULL, N , cst, ___) \ |
46 | _(KNUM, N , cst, ___) \ | 47 | _(KNUM, N , cst, ___) \ |
47 | _(KINT64, N , cst, ___) \ | 48 | _(KINT64, N , cst, ___) \ |
@@ -566,7 +567,8 @@ typedef union IRIns { | |||
566 | #define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) | 567 | #define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) |
567 | #define ir_k64(ir) \ | 568 | #define ir_k64(ir) \ |
568 | check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) | 569 | check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) |
569 | #define ir_kptr(ir) check_exp((ir)->o == IR_KPTR, mref((ir)->ptr, void)) | 570 | #define ir_kptr(ir) \ |
571 | check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void)) | ||
570 | 572 | ||
571 | LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W); | 573 | LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W); |
572 | 574 | ||
diff --git a/src/lj_iropt.h b/src/lj_iropt.h index 03029f80..43c414c1 100644 --- a/src/lj_iropt.h +++ b/src/lj_iropt.h | |||
@@ -46,7 +46,7 @@ LJ_FUNC TRef lj_ir_knum_u64(jit_State *J, uint64_t u64); | |||
46 | LJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n); | 46 | LJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n); |
47 | LJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64); | 47 | LJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64); |
48 | LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t); | 48 | LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t); |
49 | LJ_FUNC TRef lj_ir_kptr(jit_State *J, void *ptr); | 49 | LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr); |
50 | LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t); | 50 | LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t); |
51 | LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot); | 51 | LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot); |
52 | 52 | ||
@@ -66,6 +66,8 @@ static LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n) | |||
66 | #define lj_ir_kstr(J, str) lj_ir_kgc(J, obj2gco((str)), IRT_STR) | 66 | #define lj_ir_kstr(J, str) lj_ir_kgc(J, obj2gco((str)), IRT_STR) |
67 | #define lj_ir_ktab(J, tab) lj_ir_kgc(J, obj2gco((tab)), IRT_TAB) | 67 | #define lj_ir_ktab(J, tab) lj_ir_kgc(J, obj2gco((tab)), IRT_TAB) |
68 | #define lj_ir_kfunc(J, func) lj_ir_kgc(J, obj2gco((func)), IRT_FUNC) | 68 | #define lj_ir_kfunc(J, func) lj_ir_kgc(J, obj2gco((func)), IRT_FUNC) |
69 | #define lj_ir_kptr(J, ptr) lj_ir_kptr_(J, IR_KPTR, (ptr)) | ||
70 | #define lj_ir_kkptr(J, ptr) lj_ir_kptr_(J, IR_KKPTR, (ptr)) | ||
69 | 71 | ||
70 | /* Special FP constants. */ | 72 | /* Special FP constants. */ |
71 | #define lj_ir_knum_zero(J) lj_ir_knum_u64(J, U64x(00000000,00000000)) | 73 | #define lj_ir_knum_zero(J) lj_ir_knum_u64(J, U64x(00000000,00000000)) |
diff --git a/src/lj_opt_fold.c b/src/lj_opt_fold.c index e79e7ab3..bc53b168 100644 --- a/src/lj_opt_fold.c +++ b/src/lj_opt_fold.c | |||
@@ -385,7 +385,7 @@ LJFOLDF(kfold_int64comp0) | |||
385 | 385 | ||
386 | /* -- Constant folding for strings ---------------------------------------- */ | 386 | /* -- Constant folding for strings ---------------------------------------- */ |
387 | 387 | ||
388 | LJFOLD(SNEW KPTR KINT) | 388 | LJFOLD(SNEW KKPTR KINT) |
389 | LJFOLDF(kfold_snew_kptr) | 389 | LJFOLDF(kfold_snew_kptr) |
390 | { | 390 | { |
391 | GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i); | 391 | GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i); |
@@ -405,7 +405,7 @@ LJFOLDF(kfold_strref) | |||
405 | { | 405 | { |
406 | GCstr *str = ir_kstr(fleft); | 406 | GCstr *str = ir_kstr(fleft); |
407 | lua_assert((MSize)fright->i < str->len); | 407 | lua_assert((MSize)fright->i < str->len); |
408 | return lj_ir_kptr(J, (char *)strdata(str) + fright->i); | 408 | return lj_ir_kkptr(J, (char *)strdata(str) + fright->i); |
409 | } | 409 | } |
410 | 410 | ||
411 | LJFOLD(STRREF SNEW any) | 411 | LJFOLD(STRREF SNEW any) |
@@ -451,11 +451,13 @@ LJFOLDF(kfold_add_kgc) | |||
451 | #else | 451 | #else |
452 | ptrdiff_t ofs = fright->i; | 452 | ptrdiff_t ofs = fright->i; |
453 | #endif | 453 | #endif |
454 | return lj_ir_kptr(J, (char *)o + ofs); | 454 | return lj_ir_kkptr(J, (char *)o + ofs); |
455 | } | 455 | } |
456 | 456 | ||
457 | LJFOLD(ADD KPTR KINT) | 457 | LJFOLD(ADD KPTR KINT) |
458 | LJFOLD(ADD KPTR KINT64) | 458 | LJFOLD(ADD KPTR KINT64) |
459 | LJFOLD(ADD KKPTR KINT) | ||
460 | LJFOLD(ADD KKPTR KINT64) | ||
459 | LJFOLDF(kfold_add_kptr) | 461 | LJFOLDF(kfold_add_kptr) |
460 | { | 462 | { |
461 | void *p = ir_kptr(fleft); | 463 | void *p = ir_kptr(fleft); |
@@ -464,7 +466,7 @@ LJFOLDF(kfold_add_kptr) | |||
464 | #else | 466 | #else |
465 | ptrdiff_t ofs = fright->i; | 467 | ptrdiff_t ofs = fright->i; |
466 | #endif | 468 | #endif |
467 | return lj_ir_kptr(J, (char *)p + ofs); | 469 | return lj_ir_kptr_(J, fleft->o, (char *)p + ofs); |
468 | } | 470 | } |
469 | 471 | ||
470 | /* -- Constant folding of conversions ------------------------------------- */ | 472 | /* -- Constant folding of conversions ------------------------------------- */ |
@@ -1574,8 +1576,8 @@ LJFOLD(ALOAD any) | |||
1574 | LJFOLDX(lj_opt_fwd_aload) | 1576 | LJFOLDX(lj_opt_fwd_aload) |
1575 | 1577 | ||
1576 | /* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */ | 1578 | /* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */ |
1577 | LJFOLD(HLOAD KPTR) | 1579 | LJFOLD(HLOAD KKPTR) |
1578 | LJFOLDF(kfold_hload_kptr) | 1580 | LJFOLDF(kfold_hload_kkptr) |
1579 | { | 1581 | { |
1580 | UNUSED(J); | 1582 | UNUSED(J); |
1581 | lua_assert(ir_kptr(fleft) == niltvg(J2G(J))); | 1583 | lua_assert(ir_kptr(fleft) == niltvg(J2G(J))); |
@@ -1625,7 +1627,7 @@ LJFOLD(HREF TNEW any) | |||
1625 | LJFOLDF(fwd_href_tnew) | 1627 | LJFOLDF(fwd_href_tnew) |
1626 | { | 1628 | { |
1627 | if (lj_opt_fwd_href_nokey(J)) | 1629 | if (lj_opt_fwd_href_nokey(J)) |
1628 | return lj_ir_kptr(J, niltvg(J2G(J))); | 1630 | return lj_ir_kkptr(J, niltvg(J2G(J))); |
1629 | return NEXTFOLD; | 1631 | return NEXTFOLD; |
1630 | } | 1632 | } |
1631 | 1633 | ||
@@ -1638,7 +1640,7 @@ LJFOLDF(fwd_href_tdup) | |||
1638 | lj_ir_kvalue(J->L, &keyv, fright); | 1640 | lj_ir_kvalue(J->L, &keyv, fright); |
1639 | if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) && | 1641 | if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) && |
1640 | lj_opt_fwd_href_nokey(J)) | 1642 | lj_opt_fwd_href_nokey(J)) |
1641 | return lj_ir_kptr(J, niltvg(J2G(J))); | 1643 | return lj_ir_kkptr(J, niltvg(J2G(J))); |
1642 | return NEXTFOLD; | 1644 | return NEXTFOLD; |
1643 | } | 1645 | } |
1644 | 1646 | ||
@@ -1760,7 +1762,8 @@ LJFOLDF(fwd_sload) | |||
1760 | } | 1762 | } |
1761 | } | 1763 | } |
1762 | 1764 | ||
1763 | LJFOLD(XLOAD KPTR any) | 1765 | /* Only fold for KKPTR. The pointer _and_ the contents must be const. */ |
1766 | LJFOLD(XLOAD KKPTR any) | ||
1764 | LJFOLDF(xload_kptr) | 1767 | LJFOLDF(xload_kptr) |
1765 | { | 1768 | { |
1766 | TRef tr = kfold_xload(J, fins, ir_kptr(fleft)); | 1769 | TRef tr = kfold_xload(J, fins, ir_kptr(fleft)); |
diff --git a/src/lj_record.c b/src/lj_record.c index 4939d3af..90779f92 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -1013,7 +1013,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix) | |||
1013 | IRType t = itype2irt(oldv); | 1013 | IRType t = itype2irt(oldv); |
1014 | TRef res; | 1014 | TRef res; |
1015 | if (oldv == niltvg(J2G(J))) { | 1015 | if (oldv == niltvg(J2G(J))) { |
1016 | emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kptr(J, niltvg(J2G(J)))); | 1016 | emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J)))); |
1017 | res = TREF_NIL; | 1017 | res = TREF_NIL; |
1018 | } else { | 1018 | } else { |
1019 | res = emitir(IRTG(loadop, t), xref, 0); | 1019 | res = emitir(IRTG(loadop, t), xref, 0); |
@@ -1036,7 +1036,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix) | |||
1036 | emitir(IRTG(loadop, IRT_NIL), xref, 0); /* Guard for nil value. */ | 1036 | emitir(IRTG(loadop, IRT_NIL), xref, 0); /* Guard for nil value. */ |
1037 | else if (xrefop == IR_HREF) | 1037 | else if (xrefop == IR_HREF) |
1038 | emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32), | 1038 | emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32), |
1039 | xref, lj_ir_kptr(J, niltvg(J2G(J)))); | 1039 | xref, lj_ir_kkptr(J, niltvg(J2G(J)))); |
1040 | if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) { | 1040 | if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) { |
1041 | lua_assert(hasmm); | 1041 | lua_assert(hasmm); |
1042 | goto handlemm; | 1042 | goto handlemm; |
@@ -1052,7 +1052,7 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix) | |||
1052 | } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) { | 1052 | } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) { |
1053 | /* Cannot derive that the previous value was non-nil, must do checks. */ | 1053 | /* Cannot derive that the previous value was non-nil, must do checks. */ |
1054 | if (xrefop == IR_HREF) /* Guard against store to niltv. */ | 1054 | if (xrefop == IR_HREF) /* Guard against store to niltv. */ |
1055 | emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kptr(J, niltvg(J2G(J)))); | 1055 | emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J)))); |
1056 | if (ix->idxchain) { /* Metamethod lookup required? */ | 1056 | if (ix->idxchain) { /* Metamethod lookup required? */ |
1057 | /* A check for NULL metatable is cheaper (hoistable) than a load. */ | 1057 | /* A check for NULL metatable is cheaper (hoistable) than a load. */ |
1058 | if (!mt) { | 1058 | if (!mt) { |