aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2016-05-23 00:34:05 +0200
committerMike Pall <mike>2016-05-23 00:34:05 +0200
commitf26679c7195e99b32f95ea9f25b47b9981e15d3d (patch)
treed50e967a387b1a9853b83b464cf819eb3607b533
parent9e99ccc360bc9784ebe5ce29d5fa2c72acfc5777 (diff)
downloadluajit-f26679c7195e99b32f95ea9f25b47b9981e15d3d.tar.gz
luajit-f26679c7195e99b32f95ea9f25b47b9981e15d3d.tar.bz2
luajit-f26679c7195e99b32f95ea9f25b47b9981e15d3d.zip
LJ_GC64: Add support for 64 bit GCobj constants in the IR.
Contributed by Peter Cawley.
-rw-r--r--src/lj_asm.c11
-rw-r--r--src/lj_ir.c29
-rw-r--r--src/lj_ir.h6
3 files changed, 33 insertions, 13 deletions
diff --git a/src/lj_asm.c b/src/lj_asm.c
index 0b3e770a..9f784cc8 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -704,6 +704,11 @@ static void ra_left(ASMState *as, Reg dest, IRRef lref)
704 } else if (ir->o == IR_KINT64) { 704 } else if (ir->o == IR_KINT64) {
705 emit_loadk64(as, dest, ir); 705 emit_loadk64(as, dest, ir);
706 return; 706 return;
707#if LJ_GC64
708 } else if (ir->o == IR_KGC || ir->o == IR_KPTR || ir->o == IR_KKPTR) {
709 emit_loadk64(as, dest, ir);
710 return;
711#endif
707#endif 712#endif
708 } else if (ir->o != IR_KPRI) { 713 } else if (ir->o != IR_KPRI) {
709 lua_assert(ir->o == IR_KINT || ir->o == IR_KGC || 714 lua_assert(ir->o == IR_KINT || ir->o == IR_KGC ||
@@ -1933,7 +1938,7 @@ static void asm_tail_link(ASMState *as)
1933 emit_addptr(as, RID_BASE, 8*(int32_t)baseslot); 1938 emit_addptr(as, RID_BASE, 8*(int32_t)baseslot);
1934 1939
1935 if (as->J->ktrace) { /* Patch ktrace slot with the final GCtrace pointer. */ 1940 if (as->J->ktrace) { /* Patch ktrace slot with the final GCtrace pointer. */
1936 setgcref(IR(as->J->ktrace)->gcr, obj2gco(as->J->curfinal)); 1941 setgcref(IR(as->J->ktrace)[LJ_GC64].gcr, obj2gco(as->J->curfinal));
1937 IR(as->J->ktrace)->o = IR_KGC; 1942 IR(as->J->ktrace)->o = IR_KGC;
1938 } 1943 }
1939 1944
@@ -1965,8 +1970,12 @@ static void asm_setup_regsp(ASMState *as)
1965 for (ir = IR(T->nk), lastir = IR(REF_BASE); ir < lastir; ir++) { 1970 for (ir = IR(T->nk), lastir = IR(REF_BASE); ir < lastir; ir++) {
1966 ir->prev = REGSP_INIT; 1971 ir->prev = REGSP_INIT;
1967 if (irt_is64(ir->t) && ir->o != IR_KNULL) { 1972 if (irt_is64(ir->t) && ir->o != IR_KNULL) {
1973#if LJ_GC64
1974 ir->i = 0; /* Will become non-zero only for RIP-relative addresses. */
1975#else
1968 /* Make life easier for backends by putting address of constant in i. */ 1976 /* Make life easier for backends by putting address of constant in i. */
1969 ir->i = (int32_t)(intptr_t)(ir+1); 1977 ir->i = (int32_t)(intptr_t)(ir+1);
1978#endif
1970 ir++; 1979 ir++;
1971 } 1980 }
1972 } 1981 }
diff --git a/src/lj_ir.c b/src/lj_ir.c
index 9c0a2224..0a206ebb 100644
--- a/src/lj_ir.c
+++ b/src/lj_ir.c
@@ -185,6 +185,12 @@ static LJ_AINLINE IRRef ir_nextk64(jit_State *J)
185 return ref; 185 return ref;
186} 186}
187 187
188#if LJ_GC64
189#define ir_nextkgc ir_nextk64
190#else
191#define ir_nextkgc ir_nextk
192#endif
193
188/* Intern int32_t constant. */ 194/* Intern int32_t constant. */
189TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k) 195TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k)
190{ 196{
@@ -268,15 +274,14 @@ TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t)
268{ 274{
269 IRIns *ir, *cir = J->cur.ir; 275 IRIns *ir, *cir = J->cur.ir;
270 IRRef ref; 276 IRRef ref;
271 lua_assert(!LJ_GC64); /* TODO_GC64: major changes required. */
272 lua_assert(!isdead(J2G(J), o)); 277 lua_assert(!isdead(J2G(J), o));
273 for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev) 278 for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev)
274 if (ir_kgc(&cir[ref]) == o) 279 if (ir_kgc(&cir[ref]) == o)
275 goto found; 280 goto found;
276 ref = ir_nextk(J); 281 ref = ir_nextkgc(J);
277 ir = IR(ref); 282 ir = IR(ref);
278 /* NOBARRIER: Current trace is a GC root. */ 283 /* NOBARRIER: Current trace is a GC root. */
279 setgcref(ir->gcr, o); 284 setgcref(ir[LJ_GC64].gcr, o);
280 ir->t.irt = (uint8_t)t; 285 ir->t.irt = (uint8_t)t;
281 ir->o = IR_KGC; 286 ir->o = IR_KGC;
282 ir->prev = J->chain[IR_KGC]; 287 ir->prev = J->chain[IR_KGC];
@@ -288,33 +293,39 @@ found:
288/* Allocate GCtrace constant placeholder (no interning). */ 293/* Allocate GCtrace constant placeholder (no interning). */
289TRef lj_ir_ktrace(jit_State *J) 294TRef lj_ir_ktrace(jit_State *J)
290{ 295{
291 IRRef ref = ir_nextk(J); 296 IRRef ref = ir_nextkgc(J);
292 IRIns *ir = IR(ref); 297 IRIns *ir = IR(ref);
293 lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE); 298 lua_assert(irt_toitype_(IRT_P64) == LJ_TTRACE);
294 ir->t.irt = IRT_P64; 299 ir->t.irt = IRT_P64;
295 ir->o = IR_KNULL; /* Not IR_KGC yet, but same size. */ 300 ir->o = LJ_GC64 ? IR_KNUM : IR_KNULL; /* Not IR_KGC yet, but same size. */
296 ir->prev = 0; 301 ir->prev = 0;
297 return TREF(ref, IRT_P64); 302 return TREF(ref, IRT_P64);
298} 303}
299 304
300/* Intern 32 bit pointer constant. */ 305/* Intern pointer constant. */
301TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr) 306TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr)
302{ 307{
303 IRIns *ir, *cir = J->cur.ir; 308 IRIns *ir, *cir = J->cur.ir;
304 IRRef ref; 309 IRRef ref;
310#if LJ_64 && !LJ_GC64
305 lua_assert((void *)(uintptr_t)u32ptr(ptr) == ptr); 311 lua_assert((void *)(uintptr_t)u32ptr(ptr) == ptr);
312#endif
306 for (ref = J->chain[op]; ref; ref = cir[ref].prev) 313 for (ref = J->chain[op]; ref; ref = cir[ref].prev)
307 if (ir_kptr(&cir[ref]) == ptr) 314 if (ir_kptr(&cir[ref]) == ptr)
308 goto found; 315 goto found;
316#if LJ_GC64
317 ref = ir_nextk64(J);
318#else
309 ref = ir_nextk(J); 319 ref = ir_nextk(J);
320#endif
310 ir = IR(ref); 321 ir = IR(ref);
311 setmref(ir->ptr, ptr); 322 setmref(ir[LJ_GC64].ptr, ptr);
312 ir->t.irt = IRT_P32; 323 ir->t.irt = IRT_PGC;
313 ir->o = op; 324 ir->o = op;
314 ir->prev = J->chain[op]; 325 ir->prev = J->chain[op];
315 J->chain[op] = (IRRef1)ref; 326 J->chain[op] = (IRRef1)ref;
316found: 327found:
317 return TREF(ref, IRT_P32); 328 return TREF(ref, IRT_PGC);
318} 329}
319 330
320/* Intern typed NULL constant. */ 331/* Intern typed NULL constant. */
diff --git a/src/lj_ir.h b/src/lj_ir.h
index 03377ec1..8b2fe638 100644
--- a/src/lj_ir.h
+++ b/src/lj_ir.h
@@ -557,8 +557,7 @@ typedef union IRIns {
557 TValue tv; /* TValue constant (overlaps entire slot). */ 557 TValue tv; /* TValue constant (overlaps entire slot). */
558} IRIns; 558} IRIns;
559 559
560/* TODO_GC64: major changes required. */ 560#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)[LJ_GC64].gcr))
561#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)->gcr))
562#define ir_kstr(ir) (gco2str(ir_kgc((ir)))) 561#define ir_kstr(ir) (gco2str(ir_kgc((ir))))
563#define ir_ktab(ir) (gco2tab(ir_kgc((ir)))) 562#define ir_ktab(ir) (gco2tab(ir_kgc((ir))))
564#define ir_kfunc(ir) (gco2func(ir_kgc((ir)))) 563#define ir_kfunc(ir) (gco2func(ir_kgc((ir))))
@@ -568,7 +567,8 @@ typedef union IRIns {
568#define ir_k64(ir) \ 567#define ir_k64(ir) \
569 check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, &(ir)[1].tv) 568 check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, &(ir)[1].tv)
570#define ir_kptr(ir) \ 569#define ir_kptr(ir) \
571 check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void)) 570 check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, \
571 mref((ir)[LJ_GC64].ptr, void))
572 572
573/* A store or any other op with a non-weak guard has a side-effect. */ 573/* A store or any other op with a non-weak guard has a side-effect. */
574static LJ_AINLINE int ir_sideeff(IRIns *ir) 574static LJ_AINLINE int ir_sideeff(IRIns *ir)