aboutsummaryrefslogtreecommitdiff
path: root/src/lj_ir.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_ir.h')
-rw-r--r--src/lj_ir.h87
1 files changed, 63 insertions, 24 deletions
diff --git a/src/lj_ir.h b/src/lj_ir.h
index ac51dc79..0340f3c2 100644
--- a/src/lj_ir.h
+++ b/src/lj_ir.h
@@ -40,6 +40,7 @@
40 _(USE, S , ref, ___) \ 40 _(USE, S , ref, ___) \
41 _(PHI, S , ref, ref) \ 41 _(PHI, S , ref, ref) \
42 _(RENAME, S , ref, lit) \ 42 _(RENAME, S , ref, lit) \
43 _(PROF, S , ___, ___) \
43 \ 44 \
44 /* Constants. */ \ 45 /* Constants. */ \
45 _(KPRI, N , ___, ___) \ 46 _(KPRI, N , ___, ___) \
@@ -74,7 +75,6 @@
74 _(NEG, N , ref, ref) \ 75 _(NEG, N , ref, ref) \
75 \ 76 \
76 _(ABS, N , ref, ref) \ 77 _(ABS, N , ref, ref) \
77 _(ATAN2, N , ref, ref) \
78 _(LDEXP, N , ref, ref) \ 78 _(LDEXP, N , ref, ref) \
79 _(MIN, C , ref, ref) \ 79 _(MIN, C , ref, ref) \
80 _(MAX, C , ref, ref) \ 80 _(MAX, C , ref, ref) \
@@ -96,6 +96,7 @@
96 _(UREFC, LW, ref, lit) \ 96 _(UREFC, LW, ref, lit) \
97 _(FREF, R , ref, lit) \ 97 _(FREF, R , ref, lit) \
98 _(STRREF, N , ref, ref) \ 98 _(STRREF, N , ref, ref) \
99 _(LREF, L , ___, ___) \
99 \ 100 \
100 /* Loads and Stores. These must be in the same order. */ \ 101 /* Loads and Stores. These must be in the same order. */ \
101 _(ALOAD, L , ref, ___) \ 102 _(ALOAD, L , ref, ___) \
@@ -105,6 +106,7 @@
105 _(XLOAD, L , ref, lit) \ 106 _(XLOAD, L , ref, lit) \
106 _(SLOAD, L , lit, lit) \ 107 _(SLOAD, L , lit, lit) \
107 _(VLOAD, L , ref, ___) \ 108 _(VLOAD, L , ref, ___) \
109 _(ALEN, L , ref, ref) \
108 \ 110 \
109 _(ASTORE, S , ref, ref) \ 111 _(ASTORE, S , ref, ref) \
110 _(HSTORE, S , ref, ref) \ 112 _(HSTORE, S , ref, ref) \
@@ -120,6 +122,11 @@
120 _(CNEW, AW, ref, ref) \ 122 _(CNEW, AW, ref, ref) \
121 _(CNEWI, NW, ref, ref) /* CSE is ok, not marked as A. */ \ 123 _(CNEWI, NW, ref, ref) /* CSE is ok, not marked as A. */ \
122 \ 124 \
125 /* Buffer operations. */ \
126 _(BUFHDR, L , ref, lit) \
127 _(BUFPUT, L , ref, ref) \
128 _(BUFSTR, A , ref, ref) \
129 \
123 /* Barriers. */ \ 130 /* Barriers. */ \
124 _(TBAR, S , ref, ___) \ 131 _(TBAR, S , ref, ___) \
125 _(OBAR, S , ref, ref) \ 132 _(OBAR, S , ref, ref) \
@@ -128,11 +135,12 @@
128 /* Type conversions. */ \ 135 /* Type conversions. */ \
129 _(CONV, N , ref, lit) \ 136 _(CONV, N , ref, lit) \
130 _(TOBIT, N , ref, ref) \ 137 _(TOBIT, N , ref, ref) \
131 _(TOSTR, N , ref, ___) \ 138 _(TOSTR, N , ref, lit) \
132 _(STRTO, N , ref, ___) \ 139 _(STRTO, N , ref, ___) \
133 \ 140 \
134 /* Calls. */ \ 141 /* Calls. */ \
135 _(CALLN, N , ref, lit) \ 142 _(CALLN, N , ref, lit) \
143 _(CALLA, A , ref, lit) \
136 _(CALLL, L , ref, lit) \ 144 _(CALLL, L , ref, lit) \
137 _(CALLS, S , ref, lit) \ 145 _(CALLS, S , ref, lit) \
138 _(CALLXS, S , ref, ref) \ 146 _(CALLXS, S , ref, ref) \
@@ -170,8 +178,7 @@ LJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE);
170/* FPMATH sub-functions. ORDER FPM. */ 178/* FPMATH sub-functions. ORDER FPM. */
171#define IRFPMDEF(_) \ 179#define IRFPMDEF(_) \
172 _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \ 180 _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \
173 _(SQRT) _(EXP) _(EXP2) _(LOG) _(LOG2) _(LOG10) \ 181 _(SQRT) _(LOG) _(LOG2) \
174 _(SIN) _(COS) _(TAN) \
175 _(OTHER) 182 _(OTHER)
176 183
177typedef enum { 184typedef enum {
@@ -186,6 +193,8 @@ IRFPMDEF(FPMENUM)
186 _(STR_LEN, offsetof(GCstr, len)) \ 193 _(STR_LEN, offsetof(GCstr, len)) \
187 _(FUNC_ENV, offsetof(GCfunc, l.env)) \ 194 _(FUNC_ENV, offsetof(GCfunc, l.env)) \
188 _(FUNC_PC, offsetof(GCfunc, l.pc)) \ 195 _(FUNC_PC, offsetof(GCfunc, l.pc)) \
196 _(FUNC_FFID, offsetof(GCfunc, l.ffid)) \
197 _(THREAD_ENV, offsetof(lua_State, env)) \
189 _(TAB_META, offsetof(GCtab, metatable)) \ 198 _(TAB_META, offsetof(GCtab, metatable)) \
190 _(TAB_ARRAY, offsetof(GCtab, array)) \ 199 _(TAB_ARRAY, offsetof(GCtab, array)) \
191 _(TAB_NODE, offsetof(GCtab, node)) \ 200 _(TAB_NODE, offsetof(GCtab, node)) \
@@ -210,7 +219,7 @@ IRFLDEF(FLENUM)
210 219
211/* SLOAD mode bits, stored in op2. */ 220/* SLOAD mode bits, stored in op2. */
212#define IRSLOAD_PARENT 0x01 /* Coalesce with parent trace. */ 221#define IRSLOAD_PARENT 0x01 /* Coalesce with parent trace. */
213#define IRSLOAD_FRAME 0x02 /* Load hiword of frame. */ 222#define IRSLOAD_FRAME 0x02 /* Load 32 bits of ftsz. */
214#define IRSLOAD_TYPECHECK 0x04 /* Needs type check. */ 223#define IRSLOAD_TYPECHECK 0x04 /* Needs type check. */
215#define IRSLOAD_CONVERT 0x08 /* Number to integer conversion. */ 224#define IRSLOAD_CONVERT 0x08 /* Number to integer conversion. */
216#define IRSLOAD_READONLY 0x10 /* Read-only, omit slot store. */ 225#define IRSLOAD_READONLY 0x10 /* Read-only, omit slot store. */
@@ -221,13 +230,16 @@ IRFLDEF(FLENUM)
221#define IRXLOAD_VOLATILE 2 /* Load from volatile data. */ 230#define IRXLOAD_VOLATILE 2 /* Load from volatile data. */
222#define IRXLOAD_UNALIGNED 4 /* Unaligned load. */ 231#define IRXLOAD_UNALIGNED 4 /* Unaligned load. */
223 232
233/* BUFHDR mode, stored in op2. */
234#define IRBUFHDR_RESET 0 /* Reset buffer. */
235#define IRBUFHDR_APPEND 1 /* Append to buffer. */
236
224/* CONV mode, stored in op2. */ 237/* CONV mode, stored in op2. */
225#define IRCONV_SRCMASK 0x001f /* Source IRType. */ 238#define IRCONV_SRCMASK 0x001f /* Source IRType. */
226#define IRCONV_DSTMASK 0x03e0 /* Dest. IRType (also in ir->t). */ 239#define IRCONV_DSTMASK 0x03e0 /* Dest. IRType (also in ir->t). */
227#define IRCONV_DSH 5 240#define IRCONV_DSH 5
228#define IRCONV_NUM_INT ((IRT_NUM<<IRCONV_DSH)|IRT_INT) 241#define IRCONV_NUM_INT ((IRT_NUM<<IRCONV_DSH)|IRT_INT)
229#define IRCONV_INT_NUM ((IRT_INT<<IRCONV_DSH)|IRT_NUM) 242#define IRCONV_INT_NUM ((IRT_INT<<IRCONV_DSH)|IRT_NUM)
230#define IRCONV_TRUNC 0x0400 /* Truncate number to integer. */
231#define IRCONV_SEXT 0x0800 /* Sign-extend integer to integer. */ 243#define IRCONV_SEXT 0x0800 /* Sign-extend integer to integer. */
232#define IRCONV_MODEMASK 0x0fff 244#define IRCONV_MODEMASK 0x0fff
233#define IRCONV_CONVMASK 0xf000 245#define IRCONV_CONVMASK 0xf000
@@ -238,6 +250,11 @@ IRFLDEF(FLENUM)
238#define IRCONV_INDEX (2<<IRCONV_CSH) /* Check + special backprop rules. */ 250#define IRCONV_INDEX (2<<IRCONV_CSH) /* Check + special backprop rules. */
239#define IRCONV_CHECK (3<<IRCONV_CSH) /* Number checked for integerness. */ 251#define IRCONV_CHECK (3<<IRCONV_CSH) /* Number checked for integerness. */
240 252
253/* TOSTR mode, stored in op2. */
254#define IRTOSTR_INT 0 /* Convert integer to string. */
255#define IRTOSTR_NUM 1 /* Convert number to string. */
256#define IRTOSTR_CHAR 2 /* Convert char value to string. */
257
241/* -- IR operands --------------------------------------------------------- */ 258/* -- IR operands --------------------------------------------------------- */
242 259
243/* IR operand mode (2 bit). */ 260/* IR operand mode (2 bit). */
@@ -276,7 +293,9 @@ LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1];
276 293
277/* -- IR instruction types ------------------------------------------------ */ 294/* -- IR instruction types ------------------------------------------------ */
278 295
279/* Map of itypes to non-negative numbers. ORDER LJ_T. 296#define IRTSIZE_PGC (LJ_GC64 ? 8 : 4)
297
298/* Map of itypes to non-negative numbers and their sizes. ORDER LJ_T.
280** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for 299** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for
281** IRT_P32 and IRT_P64, which never escape the IR. 300** IRT_P32 and IRT_P64, which never escape the IR.
282** The various integers are only used in the IR and can only escape to 301** The various integers are only used in the IR and can only escape to
@@ -284,12 +303,13 @@ LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1];
284** contiguous and next to IRT_NUM (see the typerange macros below). 303** contiguous and next to IRT_NUM (see the typerange macros below).
285*/ 304*/
286#define IRTDEF(_) \ 305#define IRTDEF(_) \
287 _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) _(STR, 4) \ 306 _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) \
288 _(P32, 4) _(THREAD, 4) _(PROTO, 4) _(FUNC, 4) _(P64, 8) _(CDATA, 4) \ 307 _(STR, IRTSIZE_PGC) _(P32, 4) _(THREAD, IRTSIZE_PGC) _(PROTO, IRTSIZE_PGC) \
289 _(TAB, 4) _(UDATA, 4) \ 308 _(FUNC, IRTSIZE_PGC) _(P64, 8) _(CDATA, IRTSIZE_PGC) _(TAB, IRTSIZE_PGC) \
309 _(UDATA, IRTSIZE_PGC) \
290 _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \ 310 _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \
291 _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \ 311 _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \
292 _(SOFTFP, 4) /* There is room for 9 more types. */ 312 _(SOFTFP, 4) /* There is room for 8 more types. */
293 313
294/* IR result type and flags (8 bit). */ 314/* IR result type and flags (8 bit). */
295typedef enum { 315typedef enum {
@@ -300,6 +320,8 @@ IRTDEF(IRTENUM)
300 320
301 /* Native pointer type and the corresponding integer type. */ 321 /* Native pointer type and the corresponding integer type. */
302 IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32, 322 IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32,
323 IRT_PGC = LJ_GC64 ? IRT_P64 : IRT_P32,
324 IRT_IGC = LJ_GC64 ? IRT_I64 : IRT_INT,
303 IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT, 325 IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT,
304 IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32, 326 IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32,
305 327
@@ -353,7 +375,14 @@ typedef struct IRType1 { uint8_t irt; } IRType1;
353#define irt_isaddr(t) (irt_typerange((t), IRT_LIGHTUD, IRT_UDATA)) 375#define irt_isaddr(t) (irt_typerange((t), IRT_LIGHTUD, IRT_UDATA))
354#define irt_isint64(t) (irt_typerange((t), IRT_I64, IRT_U64)) 376#define irt_isint64(t) (irt_typerange((t), IRT_I64, IRT_U64))
355 377
356#if LJ_64 378#if LJ_GC64
379/* Include IRT_NIL, so IR(ASMREF_L) (aka REF_NIL) is considered 64 bit. */
380#define IRT_IS64 \
381 ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|\
382 (1u<<IRT_LIGHTUD)|(1u<<IRT_STR)|(1u<<IRT_THREAD)|(1u<<IRT_PROTO)|\
383 (1u<<IRT_FUNC)|(1u<<IRT_CDATA)|(1u<<IRT_TAB)|(1u<<IRT_UDATA)|\
384 (1u<<IRT_NIL))
385#elif LJ_64
357#define IRT_IS64 \ 386#define IRT_IS64 \
358 ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|(1u<<IRT_LIGHTUD)) 387 ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|(1u<<IRT_LIGHTUD))
359#else 388#else
@@ -374,7 +403,7 @@ static LJ_AINLINE IRType itype2irt(const TValue *tv)
374 return IRT_INT; 403 return IRT_INT;
375 else if (tvisnum(tv)) 404 else if (tvisnum(tv))
376 return IRT_NUM; 405 return IRT_NUM;
377#if LJ_64 406#if LJ_64 && !LJ_GC64
378 else if (tvislightud(tv)) 407 else if (tvislightud(tv))
379 return IRT_LIGHTUD; 408 return IRT_LIGHTUD;
380#endif 409#endif
@@ -384,11 +413,12 @@ static LJ_AINLINE IRType itype2irt(const TValue *tv)
384 413
385static LJ_AINLINE uint32_t irt_toitype_(IRType t) 414static LJ_AINLINE uint32_t irt_toitype_(IRType t)
386{ 415{
387 lua_assert(!LJ_64 || t != IRT_LIGHTUD); 416 lj_assertX(!LJ_64 || LJ_GC64 || t != IRT_LIGHTUD,
417 "no plain type tag for lightuserdata");
388 if (LJ_DUALNUM && t > IRT_NUM) { 418 if (LJ_DUALNUM && t > IRT_NUM) {
389 return LJ_TISNUM; 419 return LJ_TISNUM;
390 } else { 420 } else {
391 lua_assert(t <= IRT_NUM); 421 lj_assertX(t <= IRT_NUM, "no plain type tag for IR type %d", t);
392 return ~(uint32_t)t; 422 return ~(uint32_t)t;
393 } 423 }
394} 424}
@@ -464,6 +494,7 @@ typedef uint32_t TRef;
464#define tref_isnil(tr) (tref_istype((tr), IRT_NIL)) 494#define tref_isnil(tr) (tref_istype((tr), IRT_NIL))
465#define tref_isfalse(tr) (tref_istype((tr), IRT_FALSE)) 495#define tref_isfalse(tr) (tref_istype((tr), IRT_FALSE))
466#define tref_istrue(tr) (tref_istype((tr), IRT_TRUE)) 496#define tref_istrue(tr) (tref_istype((tr), IRT_TRUE))
497#define tref_islightud(tr) (tref_istype((tr), IRT_LIGHTUD))
467#define tref_isstr(tr) (tref_istype((tr), IRT_STR)) 498#define tref_isstr(tr) (tref_istype((tr), IRT_STR))
468#define tref_isfunc(tr) (tref_istype((tr), IRT_FUNC)) 499#define tref_isfunc(tr) (tref_istype((tr), IRT_FUNC))
469#define tref_iscdata(tr) (tref_istype((tr), IRT_CDATA)) 500#define tref_iscdata(tr) (tref_istype((tr), IRT_CDATA))
@@ -496,7 +527,9 @@ typedef uint32_t TRef;
496** +-------+-------+---+---+---+---+ 527** +-------+-------+---+---+---+---+
497** | op1 | op2 | t | o | r | s | 528** | op1 | op2 | t | o | r | s |
498** +-------+-------+---+---+---+---+ 529** +-------+-------+---+---+---+---+
499** | op12/i/gco | ot | prev | (alternative fields in union) 530** | op12/i/gco32 | ot | prev | (alternative fields in union)
531** +-------+-------+---+---+---+---+
532** | TValue/gco64 | (2nd IR slot for 64 bit constants)
500** +---------------+-------+-------+ 533** +---------------+-------+-------+
501** 32 16 16 534** 32 16 16
502** 535**
@@ -524,21 +557,27 @@ typedef union IRIns {
524 ) 557 )
525 }; 558 };
526 int32_t i; /* 32 bit signed integer literal (overlaps op12). */ 559 int32_t i; /* 32 bit signed integer literal (overlaps op12). */
527 GCRef gcr; /* GCobj constant (overlaps op12). */ 560 GCRef gcr; /* GCobj constant (overlaps op12 or entire slot). */
528 MRef ptr; /* Pointer constant (overlaps op12). */ 561 MRef ptr; /* Pointer constant (overlaps op12 or entire slot). */
562 TValue tv; /* TValue constant (overlaps entire slot). */
529} IRIns; 563} IRIns;
530 564
531#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)->gcr)) 565#define ir_isk64(ir) \
566 ((ir)->o == IR_KNUM || (ir)->o == IR_KINT64 || \
567 (LJ_GC64 && \
568 ((ir)->o == IR_KGC || (ir)->o == IR_KPTR || (ir)->o == IR_KKPTR)))
569
570#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)[LJ_GC64].gcr))
532#define ir_kstr(ir) (gco2str(ir_kgc((ir)))) 571#define ir_kstr(ir) (gco2str(ir_kgc((ir))))
533#define ir_ktab(ir) (gco2tab(ir_kgc((ir)))) 572#define ir_ktab(ir) (gco2tab(ir_kgc((ir))))
534#define ir_kfunc(ir) (gco2func(ir_kgc((ir)))) 573#define ir_kfunc(ir) (gco2func(ir_kgc((ir))))
535#define ir_kcdata(ir) (gco2cd(ir_kgc((ir)))) 574#define ir_kcdata(ir) (gco2cd(ir_kgc((ir))))
536#define ir_knum(ir) check_exp((ir)->o == IR_KNUM, mref((ir)->ptr, cTValue)) 575#define ir_knum(ir) check_exp((ir)->o == IR_KNUM, &(ir)[1].tv)
537#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue)) 576#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, &(ir)[1].tv)
538#define ir_k64(ir) \ 577#define ir_k64(ir) check_exp(ir_isk64(ir), &(ir)[1].tv)
539 check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
540#define ir_kptr(ir) \ 578#define ir_kptr(ir) \
541 check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void)) 579 check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, \
580 mref((ir)[LJ_GC64].ptr, void))
542 581
543/* A store or any other op with a non-weak guard has a side-effect. */ 582/* A store or any other op with a non-weak guard has a side-effect. */
544static LJ_AINLINE int ir_sideeff(IRIns *ir) 583static LJ_AINLINE int ir_sideeff(IRIns *ir)