diff options
author | Mike Pall <mike> | 2009-12-08 20:35:29 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2009-12-08 20:35:29 +0100 |
commit | 3f1f9e11f4f699ae94182d4cba158092f434a7f6 (patch) | |
tree | 88fbb674a21a1d554d4b1ee9d4ef2c5fed6a1d88 /src/lj_ir.h | |
parent | 5287b9326479ea2b7dddd6f642673e58e5a7f354 (diff) | |
download | luajit-3f1f9e11f4f699ae94182d4cba158092f434a7f6.tar.gz luajit-3f1f9e11f4f699ae94182d4cba158092f434a7f6.tar.bz2 luajit-3f1f9e11f4f699ae94182d4cba158092f434a7f6.zip |
Fast forward to sync public repo.
Compile math.sinh(), math.cosh(), math.tanh() and math.random().
Compile various io.*() functions.
Drive the GC forward on string allocations in the parser.
Improve KNUM fuse vs. load heuristics.
Add abstract C call handling to IR.
Diffstat (limited to 'src/lj_ir.h')
-rw-r--r-- | src/lj_ir.h | 114 |
1 files changed, 97 insertions, 17 deletions
diff --git a/src/lj_ir.h b/src/lj_ir.h index a6973a81..9a7e711d 100644 --- a/src/lj_ir.h +++ b/src/lj_ir.h | |||
@@ -8,6 +8,8 @@ | |||
8 | 8 | ||
9 | #include "lj_obj.h" | 9 | #include "lj_obj.h" |
10 | 10 | ||
11 | /* -- IR instructions ----------------------------------------------------- */ | ||
12 | |||
11 | /* IR instruction definition. Order matters, see below. */ | 13 | /* IR instruction definition. Order matters, see below. */ |
12 | #define IRDEF(_) \ | 14 | #define IRDEF(_) \ |
13 | /* Miscellaneous ops. */ \ | 15 | /* Miscellaneous ops. */ \ |
@@ -101,13 +103,12 @@ | |||
101 | _(USTORE, S , ref, ref) \ | 103 | _(USTORE, S , ref, ref) \ |
102 | _(FSTORE, S , ref, ref) \ | 104 | _(FSTORE, S , ref, ref) \ |
103 | \ | 105 | \ |
104 | /* String ops. */ \ | 106 | /* Allocations. */ \ |
105 | _(SNEW, N , ref, ref) \ | 107 | _(SNEW, N , ref, ref) /* CSE is ok, so not marked as A. */ \ |
106 | \ | ||
107 | /* Table ops. */ \ | ||
108 | _(TNEW, A , lit, lit) \ | 108 | _(TNEW, A , lit, lit) \ |
109 | _(TDUP, A , ref, ___) \ | 109 | _(TDUP, A , ref, ___) \ |
110 | _(TLEN, L , ref, ___) \ | 110 | \ |
111 | /* Write barriers. */ \ | ||
111 | _(TBAR, S , ref, ___) \ | 112 | _(TBAR, S , ref, ___) \ |
112 | _(OBAR, S , ref, ref) \ | 113 | _(OBAR, S , ref, ref) \ |
113 | \ | 114 | \ |
@@ -118,6 +119,12 @@ | |||
118 | _(TOSTR, N , ref, ___) \ | 119 | _(TOSTR, N , ref, ___) \ |
119 | _(STRTO, G , ref, ___) \ | 120 | _(STRTO, G , ref, ___) \ |
120 | \ | 121 | \ |
122 | /* Calls. */ \ | ||
123 | _(CALLN, N , ref, lit) \ | ||
124 | _(CALLL, L , ref, lit) \ | ||
125 | _(CALLS, S , ref, lit) \ | ||
126 | _(CARG, N , ref, ref) \ | ||
127 | \ | ||
121 | /* End of list. */ | 128 | /* End of list. */ |
122 | 129 | ||
123 | /* IR opcodes (max. 256). */ | 130 | /* IR opcodes (max. 256). */ |
@@ -144,6 +151,8 @@ LJ_STATIC_ASSERT((int)IR_HLOAD + IRDELTA_L2S == (int)IR_HSTORE); | |||
144 | LJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE); | 151 | LJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE); |
145 | LJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE); | 152 | LJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE); |
146 | 153 | ||
154 | /* -- Named IR literals --------------------------------------------------- */ | ||
155 | |||
147 | /* FPMATH sub-functions. ORDER FPM. */ | 156 | /* FPMATH sub-functions. ORDER FPM. */ |
148 | #define IRFPMDEF(_) \ | 157 | #define IRFPMDEF(_) \ |
149 | _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \ | 158 | _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \ |
@@ -158,20 +167,22 @@ IRFPMDEF(FPMENUM) | |||
158 | IRFPM__MAX | 167 | IRFPM__MAX |
159 | } IRFPMathOp; | 168 | } IRFPMathOp; |
160 | 169 | ||
161 | /* FLOAD field IDs. */ | 170 | /* FLOAD fields. */ |
162 | #define IRFLDEF(_) \ | 171 | #define IRFLDEF(_) \ |
163 | _(STR_LEN, GCstr, len) \ | 172 | _(STR_LEN, offsetof(GCstr, len)) \ |
164 | _(FUNC_ENV, GCfunc, l.env) \ | 173 | _(FUNC_ENV, offsetof(GCfunc, l.env)) \ |
165 | _(TAB_META, GCtab, metatable) \ | 174 | _(TAB_META, offsetof(GCtab, metatable)) \ |
166 | _(TAB_ARRAY, GCtab, array) \ | 175 | _(TAB_ARRAY, offsetof(GCtab, array)) \ |
167 | _(TAB_NODE, GCtab, node) \ | 176 | _(TAB_NODE, offsetof(GCtab, node)) \ |
168 | _(TAB_ASIZE, GCtab, asize) \ | 177 | _(TAB_ASIZE, offsetof(GCtab, asize)) \ |
169 | _(TAB_HMASK, GCtab, hmask) \ | 178 | _(TAB_HMASK, offsetof(GCtab, hmask)) \ |
170 | _(TAB_NOMM, GCtab, nomm) \ | 179 | _(TAB_NOMM, offsetof(GCtab, nomm)) \ |
171 | _(UDATA_META, GCudata, metatable) | 180 | _(UDATA_META, offsetof(GCudata, metatable)) \ |
181 | _(UDATA_UDTYPE, offsetof(GCudata, udtype)) \ | ||
182 | _(UDATA_FILE, sizeof(GCudata)) | ||
172 | 183 | ||
173 | typedef enum { | 184 | typedef enum { |
174 | #define FLENUM(name, type, field) IRFL_##name, | 185 | #define FLENUM(name, ofs) IRFL_##name, |
175 | IRFLDEF(FLENUM) | 186 | IRFLDEF(FLENUM) |
176 | #undef FLENUM | 187 | #undef FLENUM |
177 | IRFL__MAX | 188 | IRFL__MAX |
@@ -183,7 +194,8 @@ IRFLDEF(FLENUM) | |||
183 | #define IRSLOAD_PARENT 4 /* Coalesce with parent trace. */ | 194 | #define IRSLOAD_PARENT 4 /* Coalesce with parent trace. */ |
184 | 195 | ||
185 | /* XLOAD mode, stored in op2. */ | 196 | /* XLOAD mode, stored in op2. */ |
186 | #define IRXLOAD_UNALIGNED 1 | 197 | #define IRXLOAD_READONLY 1 /* Load from read-only data. */ |
198 | #define IRXLOAD_UNALIGNED 2 /* Unaligned load. */ | ||
187 | 199 | ||
188 | /* TOINT mode, stored in op2. Ordered by strength of the checks. */ | 200 | /* TOINT mode, stored in op2. Ordered by strength of the checks. */ |
189 | #define IRTOINT_CHECK 0 /* Number checked for integerness. */ | 201 | #define IRTOINT_CHECK 0 /* Number checked for integerness. */ |
@@ -191,6 +203,67 @@ IRFLDEF(FLENUM) | |||
191 | #define IRTOINT_ANY 2 /* Any FP number is ok. */ | 203 | #define IRTOINT_ANY 2 /* Any FP number is ok. */ |
192 | #define IRTOINT_TOBIT 3 /* Cache only: TOBIT conversion. */ | 204 | #define IRTOINT_TOBIT 3 /* Cache only: TOBIT conversion. */ |
193 | 205 | ||
206 | /* C call info for CALL* instructions. */ | ||
207 | typedef struct CCallInfo { | ||
208 | ASMFunction func; /* Function pointer. */ | ||
209 | uint32_t flags; /* Number of arguments and flags. */ | ||
210 | } CCallInfo; | ||
211 | |||
212 | #define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */ | ||
213 | #define CCI_NARGS_MAX 16 /* Max. # of args. */ | ||
214 | |||
215 | #define CCI_OTSHIFT 16 | ||
216 | #define CCI_OPTYPE(ci) ((ci)->flags >> CCI_OTSHIFT) /* Get op/type. */ | ||
217 | #define CCI_OPSHIFT 24 | ||
218 | #define CCI_OP(ci) ((ci)->flags >> CCI_OPSHIFT) /* Get op. */ | ||
219 | |||
220 | #define CCI_CALL_N (IR_CALLN << CCI_OPSHIFT) | ||
221 | #define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT) | ||
222 | #define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT) | ||
223 | #define CCI_CALL_FN (CCI_CALL_N|CCI_FASTCALL) | ||
224 | #define CCI_CALL_FL (CCI_CALL_L|CCI_FASTCALL) | ||
225 | #define CCI_CALL_FS (CCI_CALL_S|CCI_FASTCALL) | ||
226 | |||
227 | /* C call info flags. */ | ||
228 | #define CCI_L 0x0100 /* Implicit L arg. */ | ||
229 | #define CCI_CASTU64 0x0200 /* Cast u64 result to number. */ | ||
230 | #define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */ | ||
231 | #define CCI_FASTCALL 0x0800 /* Fastcall convention. */ | ||
232 | |||
233 | /* Function definitions for CALL* instructions. */ | ||
234 | #define IRCALLDEF(_) \ | ||
235 | _(lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \ | ||
236 | _(lj_str_new, 3, S, STR, CCI_L) \ | ||
237 | _(lj_str_tonum, 2, FN, INT, 0) \ | ||
238 | _(lj_str_fromint, 2, FN, STR, CCI_L) \ | ||
239 | _(lj_str_fromnum, 2, FN, STR, CCI_L) \ | ||
240 | _(lj_tab_new1, 2, FS, TAB, CCI_L) \ | ||
241 | _(lj_tab_dup, 2, FS, TAB, CCI_L) \ | ||
242 | _(lj_tab_newkey, 3, S, PTR, CCI_L) \ | ||
243 | _(lj_tab_len, 1, FL, INT, 0) \ | ||
244 | _(lj_gc_step_jit, 2, FS, NIL, CCI_L) \ | ||
245 | _(lj_gc_barrieruv, 2, FS, NIL, 0) \ | ||
246 | _(lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \ | ||
247 | _(sinh, 1, N, NUM, 0) \ | ||
248 | _(cosh, 1, N, NUM, 0) \ | ||
249 | _(tanh, 1, N, NUM, 0) \ | ||
250 | _(fputc, 2, S, INT, 0) \ | ||
251 | _(fwrite, 4, S, INT, 0) \ | ||
252 | _(fflush, 1, S, INT, 0) \ | ||
253 | \ | ||
254 | /* End of list. */ | ||
255 | |||
256 | typedef enum { | ||
257 | #define IRCALLENUM(name, nargs, kind, type, flags) IRCALL_##name, | ||
258 | IRCALLDEF(IRCALLENUM) | ||
259 | #undef IRCALLENUM | ||
260 | IRCALL__MAX | ||
261 | } IRCallID; | ||
262 | |||
263 | LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1]; | ||
264 | |||
265 | /* -- IR operands --------------------------------------------------------- */ | ||
266 | |||
194 | /* IR operand mode (2 bit). */ | 267 | /* IR operand mode (2 bit). */ |
195 | typedef enum { | 268 | typedef enum { |
196 | IRMref, /* IR reference. */ | 269 | IRMref, /* IR reference. */ |
@@ -227,6 +300,8 @@ typedef enum { | |||
227 | 300 | ||
228 | LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1]; | 301 | LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1]; |
229 | 302 | ||
303 | /* -- IR instruction types ------------------------------------------------ */ | ||
304 | |||
230 | /* IR result type and flags (8 bit). */ | 305 | /* IR result type and flags (8 bit). */ |
231 | typedef enum { | 306 | typedef enum { |
232 | /* Map of itypes to non-negative numbers. ORDER LJ_T */ | 307 | /* Map of itypes to non-negative numbers. ORDER LJ_T */ |
@@ -314,6 +389,8 @@ typedef struct IRType1 { uint8_t irt; } IRType1; | |||
314 | /* Stored combined IR opcode and type. */ | 389 | /* Stored combined IR opcode and type. */ |
315 | typedef uint16_t IROpT; | 390 | typedef uint16_t IROpT; |
316 | 391 | ||
392 | /* -- IR references ------------------------------------------------------- */ | ||
393 | |||
317 | /* IR references. */ | 394 | /* IR references. */ |
318 | typedef uint16_t IRRef1; /* One stored reference. */ | 395 | typedef uint16_t IRRef1; /* One stored reference. */ |
319 | typedef uint32_t IRRef2; /* Two stored references. */ | 396 | typedef uint32_t IRRef2; /* Two stored references. */ |
@@ -382,6 +459,8 @@ typedef uint32_t TRef; | |||
382 | #define TREF_FALSE (TREF_PRI(IRT_FALSE)) | 459 | #define TREF_FALSE (TREF_PRI(IRT_FALSE)) |
383 | #define TREF_TRUE (TREF_PRI(IRT_TRUE)) | 460 | #define TREF_TRUE (TREF_PRI(IRT_TRUE)) |
384 | 461 | ||
462 | /* -- IR format ----------------------------------------------------------- */ | ||
463 | |||
385 | /* IR instruction format (64 bit). | 464 | /* IR instruction format (64 bit). |
386 | ** | 465 | ** |
387 | ** 16 16 8 8 8 8 | 466 | ** 16 16 8 8 8 8 |
@@ -425,5 +504,6 @@ typedef union IRIns { | |||
425 | #define ir_ktab(ir) (gco2tab(ir_kgc((ir)))) | 504 | #define ir_ktab(ir) (gco2tab(ir_kgc((ir)))) |
426 | #define ir_kfunc(ir) (gco2func(ir_kgc((ir)))) | 505 | #define ir_kfunc(ir) (gco2func(ir_kgc((ir)))) |
427 | #define ir_knum(ir) (mref((ir)->ptr, cTValue)) | 506 | #define ir_knum(ir) (mref((ir)->ptr, cTValue)) |
507 | #define ir_kptr(ir) (mref((ir)->ptr, void)) | ||
428 | 508 | ||
429 | #endif | 509 | #endif |