diff options
Diffstat (limited to 'src/lj_jit.h')
-rw-r--r-- | src/lj_jit.h | 225 |
1 files changed, 163 insertions, 62 deletions
diff --git a/src/lj_jit.h b/src/lj_jit.h index 02850935..0b5ad4d6 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h | |||
@@ -9,71 +9,85 @@ | |||
9 | #include "lj_obj.h" | 9 | #include "lj_obj.h" |
10 | #include "lj_ir.h" | 10 | #include "lj_ir.h" |
11 | 11 | ||
12 | /* JIT engine flags. */ | 12 | /* -- JIT engine flags ---------------------------------------------------- */ |
13 | |||
14 | /* General JIT engine flags. 4 bits. */ | ||
13 | #define JIT_F_ON 0x00000001 | 15 | #define JIT_F_ON 0x00000001 |
14 | 16 | ||
15 | /* CPU-specific JIT engine flags. */ | 17 | /* CPU-specific JIT engine flags. 12 bits. Flags and strings must match. */ |
18 | #define JIT_F_CPU 0x00000010 | ||
19 | |||
16 | #if LJ_TARGET_X86ORX64 | 20 | #if LJ_TARGET_X86ORX64 |
17 | #define JIT_F_CMOV 0x00000010 | 21 | |
18 | #define JIT_F_SSE2 0x00000020 | 22 | #define JIT_F_SSE3 (JIT_F_CPU << 0) |
19 | #define JIT_F_SSE3 0x00000040 | 23 | #define JIT_F_SSE4_1 (JIT_F_CPU << 1) |
20 | #define JIT_F_SSE4_1 0x00000080 | 24 | #define JIT_F_BMI2 (JIT_F_CPU << 2) |
21 | #define JIT_F_P4 0x00000100 | 25 | |
22 | #define JIT_F_PREFER_IMUL 0x00000200 | 26 | |
23 | #define JIT_F_SPLIT_XMM 0x00000400 | 27 | #define JIT_F_CPUSTRING "\4SSE3\6SSE4.1\4BMI2" |
24 | #define JIT_F_LEA_AGU 0x00000800 | 28 | |
25 | |||
26 | /* Names for the CPU-specific flags. Must match the order above. */ | ||
27 | #define JIT_F_CPU_FIRST JIT_F_CMOV | ||
28 | #define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM" | ||
29 | #elif LJ_TARGET_ARM | 29 | #elif LJ_TARGET_ARM |
30 | #define JIT_F_ARMV6_ 0x00000010 | 30 | |
31 | #define JIT_F_ARMV6T2_ 0x00000020 | 31 | #define JIT_F_ARMV6_ (JIT_F_CPU << 0) |
32 | #define JIT_F_ARMV7 0x00000040 | 32 | #define JIT_F_ARMV6T2_ (JIT_F_CPU << 1) |
33 | #define JIT_F_VFPV2 0x00000080 | 33 | #define JIT_F_ARMV7 (JIT_F_CPU << 2) |
34 | #define JIT_F_VFPV3 0x00000100 | 34 | #define JIT_F_ARMV8 (JIT_F_CPU << 3) |
35 | 35 | #define JIT_F_VFPV2 (JIT_F_CPU << 4) | |
36 | #define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7) | 36 | #define JIT_F_VFPV3 (JIT_F_CPU << 5) |
37 | #define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7) | 37 | |
38 | #define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8) | ||
39 | #define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8) | ||
38 | #define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3) | 40 | #define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3) |
39 | 41 | ||
40 | /* Names for the CPU-specific flags. Must match the order above. */ | 42 | #define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5ARMv8\5VFPv2\5VFPv3" |
41 | #define JIT_F_CPU_FIRST JIT_F_ARMV6_ | 43 | |
42 | #define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5VFPv2\5VFPv3" | ||
43 | #elif LJ_TARGET_PPC | 44 | #elif LJ_TARGET_PPC |
44 | #define JIT_F_SQRT 0x00000010 | ||
45 | #define JIT_F_ROUND 0x00000020 | ||
46 | 45 | ||
47 | /* Names for the CPU-specific flags. Must match the order above. */ | 46 | #define JIT_F_SQRT (JIT_F_CPU << 0) |
48 | #define JIT_F_CPU_FIRST JIT_F_SQRT | 47 | #define JIT_F_ROUND (JIT_F_CPU << 1) |
48 | |||
49 | #define JIT_F_CPUSTRING "\4SQRT\5ROUND" | 49 | #define JIT_F_CPUSTRING "\4SQRT\5ROUND" |
50 | |||
50 | #elif LJ_TARGET_MIPS | 51 | #elif LJ_TARGET_MIPS |
51 | #define JIT_F_MIPS32R2 0x00000010 | ||
52 | 52 | ||
53 | /* Names for the CPU-specific flags. Must match the order above. */ | 53 | #define JIT_F_MIPSXXR2 (JIT_F_CPU << 0) |
54 | #define JIT_F_CPU_FIRST JIT_F_MIPS32R2 | 54 | |
55 | #if LJ_TARGET_MIPS32 | ||
56 | #if LJ_TARGET_MIPSR6 | ||
57 | #define JIT_F_CPUSTRING "\010MIPS32R6" | ||
58 | #else | ||
55 | #define JIT_F_CPUSTRING "\010MIPS32R2" | 59 | #define JIT_F_CPUSTRING "\010MIPS32R2" |
60 | #endif | ||
61 | #else | ||
62 | #if LJ_TARGET_MIPSR6 | ||
63 | #define JIT_F_CPUSTRING "\010MIPS64R6" | ||
56 | #else | 64 | #else |
57 | #define JIT_F_CPU_FIRST 0 | 65 | #define JIT_F_CPUSTRING "\010MIPS64R2" |
66 | #endif | ||
67 | #endif | ||
68 | |||
69 | #else | ||
70 | |||
58 | #define JIT_F_CPUSTRING "" | 71 | #define JIT_F_CPUSTRING "" |
72 | |||
59 | #endif | 73 | #endif |
60 | 74 | ||
61 | /* Optimization flags. */ | 75 | /* Optimization flags. 12 bits. */ |
76 | #define JIT_F_OPT 0x00010000 | ||
62 | #define JIT_F_OPT_MASK 0x0fff0000 | 77 | #define JIT_F_OPT_MASK 0x0fff0000 |
63 | 78 | ||
64 | #define JIT_F_OPT_FOLD 0x00010000 | 79 | #define JIT_F_OPT_FOLD (JIT_F_OPT << 0) |
65 | #define JIT_F_OPT_CSE 0x00020000 | 80 | #define JIT_F_OPT_CSE (JIT_F_OPT << 1) |
66 | #define JIT_F_OPT_DCE 0x00040000 | 81 | #define JIT_F_OPT_DCE (JIT_F_OPT << 2) |
67 | #define JIT_F_OPT_FWD 0x00080000 | 82 | #define JIT_F_OPT_FWD (JIT_F_OPT << 3) |
68 | #define JIT_F_OPT_DSE 0x00100000 | 83 | #define JIT_F_OPT_DSE (JIT_F_OPT << 4) |
69 | #define JIT_F_OPT_NARROW 0x00200000 | 84 | #define JIT_F_OPT_NARROW (JIT_F_OPT << 5) |
70 | #define JIT_F_OPT_LOOP 0x00400000 | 85 | #define JIT_F_OPT_LOOP (JIT_F_OPT << 6) |
71 | #define JIT_F_OPT_ABC 0x00800000 | 86 | #define JIT_F_OPT_ABC (JIT_F_OPT << 7) |
72 | #define JIT_F_OPT_SINK 0x01000000 | 87 | #define JIT_F_OPT_SINK (JIT_F_OPT << 8) |
73 | #define JIT_F_OPT_FUSE 0x02000000 | 88 | #define JIT_F_OPT_FUSE (JIT_F_OPT << 9) |
74 | 89 | ||
75 | /* Optimizations names for -O. Must match the order above. */ | 90 | /* Optimizations names for -O. Must match the order above. */ |
76 | #define JIT_F_OPT_FIRST JIT_F_OPT_FOLD | ||
77 | #define JIT_F_OPTSTRING \ | 91 | #define JIT_F_OPTSTRING \ |
78 | "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse" | 92 | "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse" |
79 | 93 | ||
@@ -85,6 +99,8 @@ | |||
85 | JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE) | 99 | JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE) |
86 | #define JIT_F_OPT_DEFAULT JIT_F_OPT_3 | 100 | #define JIT_F_OPT_DEFAULT JIT_F_OPT_3 |
87 | 101 | ||
102 | /* -- JIT engine parameters ----------------------------------------------- */ | ||
103 | |||
88 | #if LJ_TARGET_WINDOWS || LJ_64 | 104 | #if LJ_TARGET_WINDOWS || LJ_64 |
89 | /* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ | 105 | /* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */ |
90 | #define JIT_P_sizemcode_DEFAULT 64 | 106 | #define JIT_P_sizemcode_DEFAULT 64 |
@@ -100,6 +116,7 @@ | |||
100 | _(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \ | 116 | _(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \ |
101 | _(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \ | 117 | _(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \ |
102 | _(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \ | 118 | _(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \ |
119 | _(\011, minstitch, 0) /* Min. # of IR ins for a stitched trace. */ \ | ||
103 | \ | 120 | \ |
104 | _(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \ | 121 | _(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \ |
105 | _(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \ | 122 | _(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \ |
@@ -126,11 +143,14 @@ JIT_PARAMDEF(JIT_PARAMENUM) | |||
126 | #define JIT_PARAMSTR(len, name, value) #len #name | 143 | #define JIT_PARAMSTR(len, name, value) #len #name |
127 | #define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR) | 144 | #define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR) |
128 | 145 | ||
146 | /* -- JIT engine data structures ------------------------------------------ */ | ||
147 | |||
129 | /* Trace compiler state. */ | 148 | /* Trace compiler state. */ |
130 | typedef enum { | 149 | typedef enum { |
131 | LJ_TRACE_IDLE, /* Trace compiler idle. */ | 150 | LJ_TRACE_IDLE, /* Trace compiler idle. */ |
132 | LJ_TRACE_ACTIVE = 0x10, | 151 | LJ_TRACE_ACTIVE = 0x10, |
133 | LJ_TRACE_RECORD, /* Bytecode recording active. */ | 152 | LJ_TRACE_RECORD, /* Bytecode recording active. */ |
153 | LJ_TRACE_RECORD_1ST, /* Record 1st instruction, too. */ | ||
134 | LJ_TRACE_START, /* New trace started. */ | 154 | LJ_TRACE_START, /* New trace started. */ |
135 | LJ_TRACE_END, /* End of trace. */ | 155 | LJ_TRACE_END, /* End of trace. */ |
136 | LJ_TRACE_ASM, /* Assemble trace. */ | 156 | LJ_TRACE_ASM, /* Assemble trace. */ |
@@ -165,6 +185,7 @@ typedef struct MCLink { | |||
165 | typedef struct SnapShot { | 185 | typedef struct SnapShot { |
166 | uint32_t mapofs; /* Offset into snapshot map. */ | 186 | uint32_t mapofs; /* Offset into snapshot map. */ |
167 | IRRef1 ref; /* First IR ref for this snapshot. */ | 187 | IRRef1 ref; /* First IR ref for this snapshot. */ |
188 | uint16_t mcofs; /* Offset into machine code in MCode units. */ | ||
168 | uint8_t nslots; /* Number of valid slots. */ | 189 | uint8_t nslots; /* Number of valid slots. */ |
169 | uint8_t topslot; /* Maximum frame extent. */ | 190 | uint8_t topslot; /* Maximum frame extent. */ |
170 | uint8_t nent; /* Number of compressed entries. */ | 191 | uint8_t nent; /* Number of compressed entries. */ |
@@ -180,20 +201,35 @@ typedef uint32_t SnapEntry; | |||
180 | #define SNAP_CONT 0x020000 /* Continuation slot. */ | 201 | #define SNAP_CONT 0x020000 /* Continuation slot. */ |
181 | #define SNAP_NORESTORE 0x040000 /* No need to restore slot. */ | 202 | #define SNAP_NORESTORE 0x040000 /* No need to restore slot. */ |
182 | #define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */ | 203 | #define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */ |
204 | #define SNAP_KEYINDEX 0x100000 /* Traversal key index. */ | ||
183 | LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME); | 205 | LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME); |
184 | LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT); | 206 | LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT); |
207 | LJ_STATIC_ASSERT(SNAP_KEYINDEX == TREF_KEYINDEX); | ||
185 | 208 | ||
186 | #define SNAP(slot, flags, ref) (((SnapEntry)(slot) << 24) + (flags) + (ref)) | 209 | #define SNAP(slot, flags, ref) (((SnapEntry)(slot) << 24) + (flags) + (ref)) |
187 | #define SNAP_TR(slot, tr) \ | 210 | #define SNAP_TR(slot, tr) \ |
188 | (((SnapEntry)(slot) << 24) + ((tr) & (TREF_CONT|TREF_FRAME|TREF_REFMASK))) | 211 | (((SnapEntry)(slot) << 24) + \ |
212 | ((tr) & (TREF_KEYINDEX|TREF_CONT|TREF_FRAME|TREF_REFMASK))) | ||
213 | #if !LJ_FR2 | ||
189 | #define SNAP_MKPC(pc) ((SnapEntry)u32ptr(pc)) | 214 | #define SNAP_MKPC(pc) ((SnapEntry)u32ptr(pc)) |
215 | #endif | ||
190 | #define SNAP_MKFTSZ(ftsz) ((SnapEntry)(ftsz)) | 216 | #define SNAP_MKFTSZ(ftsz) ((SnapEntry)(ftsz)) |
191 | #define snap_ref(sn) ((sn) & 0xffff) | 217 | #define snap_ref(sn) ((sn) & 0xffff) |
192 | #define snap_slot(sn) ((BCReg)((sn) >> 24)) | 218 | #define snap_slot(sn) ((BCReg)((sn) >> 24)) |
193 | #define snap_isframe(sn) ((sn) & SNAP_FRAME) | 219 | #define snap_isframe(sn) ((sn) & SNAP_FRAME) |
194 | #define snap_pc(sn) ((const BCIns *)(uintptr_t)(sn)) | ||
195 | #define snap_setref(sn, ref) (((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref)) | 220 | #define snap_setref(sn, ref) (((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref)) |
196 | 221 | ||
222 | static LJ_AINLINE const BCIns *snap_pc(SnapEntry *sn) | ||
223 | { | ||
224 | #if LJ_FR2 | ||
225 | uint64_t pcbase; | ||
226 | memcpy(&pcbase, sn, sizeof(uint64_t)); | ||
227 | return (const BCIns *)(pcbase >> 8); | ||
228 | #else | ||
229 | return (const BCIns *)(uintptr_t)*sn; | ||
230 | #endif | ||
231 | } | ||
232 | |||
197 | /* Snapshot and exit numbers. */ | 233 | /* Snapshot and exit numbers. */ |
198 | typedef uint32_t SnapNo; | 234 | typedef uint32_t SnapNo; |
199 | typedef uint32_t ExitNo; | 235 | typedef uint32_t ExitNo; |
@@ -211,7 +247,8 @@ typedef enum { | |||
211 | LJ_TRLINK_UPREC, /* Up-recursion. */ | 247 | LJ_TRLINK_UPREC, /* Up-recursion. */ |
212 | LJ_TRLINK_DOWNREC, /* Down-recursion. */ | 248 | LJ_TRLINK_DOWNREC, /* Down-recursion. */ |
213 | LJ_TRLINK_INTERP, /* Fallback to interpreter. */ | 249 | LJ_TRLINK_INTERP, /* Fallback to interpreter. */ |
214 | LJ_TRLINK_RETURN /* Return to interpreter. */ | 250 | LJ_TRLINK_RETURN, /* Return to interpreter. */ |
251 | LJ_TRLINK_STITCH /* Trace stitching. */ | ||
215 | } TraceLink; | 252 | } TraceLink; |
216 | 253 | ||
217 | /* Trace object. */ | 254 | /* Trace object. */ |
@@ -219,6 +256,9 @@ typedef struct GCtrace { | |||
219 | GCHeader; | 256 | GCHeader; |
220 | uint16_t nsnap; /* Number of snapshots. */ | 257 | uint16_t nsnap; /* Number of snapshots. */ |
221 | IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */ | 258 | IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */ |
259 | #if LJ_GC64 | ||
260 | uint32_t unused_gc64; | ||
261 | #endif | ||
222 | GCRef gclist; | 262 | GCRef gclist; |
223 | IRIns *ir; /* IR instructions/constants. Biased with REF_BIAS. */ | 263 | IRIns *ir; /* IR instructions/constants. Biased with REF_BIAS. */ |
224 | IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */ | 264 | IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */ |
@@ -294,6 +334,16 @@ typedef struct ScEvEntry { | |||
294 | uint8_t dir; /* Direction. 1: +, 0: -. */ | 334 | uint8_t dir; /* Direction. 1: +, 0: -. */ |
295 | } ScEvEntry; | 335 | } ScEvEntry; |
296 | 336 | ||
337 | /* Reverse bytecode map (IRRef -> PC). Only for selected instructions. */ | ||
338 | typedef struct RBCHashEntry { | ||
339 | MRef pc; /* Bytecode PC. */ | ||
340 | GCRef pt; /* Prototype. */ | ||
341 | IRRef ref; /* IR reference. */ | ||
342 | } RBCHashEntry; | ||
343 | |||
344 | /* Number of slots in the reverse bytecode hash table. Must be a power of 2. */ | ||
345 | #define RBCHASH_SLOTS 8 | ||
346 | |||
297 | /* 128 bit SIMD constants. */ | 347 | /* 128 bit SIMD constants. */ |
298 | enum { | 348 | enum { |
299 | LJ_KSIMD_ABS, | 349 | LJ_KSIMD_ABS, |
@@ -301,12 +351,51 @@ enum { | |||
301 | LJ_KSIMD__MAX | 351 | LJ_KSIMD__MAX |
302 | }; | 352 | }; |
303 | 353 | ||
354 | enum { | ||
355 | #if LJ_TARGET_X86ORX64 | ||
356 | LJ_K64_TOBIT, /* 2^52 + 2^51 */ | ||
357 | LJ_K64_2P64, /* 2^64 */ | ||
358 | LJ_K64_M2P64, /* -2^64 */ | ||
359 | #if LJ_32 | ||
360 | LJ_K64_M2P64_31, /* -2^64 or -2^31 */ | ||
361 | #else | ||
362 | LJ_K64_M2P64_31 = LJ_K64_M2P64, | ||
363 | #endif | ||
364 | #endif | ||
365 | #if LJ_TARGET_MIPS | ||
366 | LJ_K64_2P31, /* 2^31 */ | ||
367 | #if LJ_64 | ||
368 | LJ_K64_2P63, /* 2^63 */ | ||
369 | LJ_K64_M2P64, /* -2^64 */ | ||
370 | #endif | ||
371 | #endif | ||
372 | LJ_K64__MAX, | ||
373 | }; | ||
374 | |||
375 | enum { | ||
376 | #if LJ_TARGET_X86ORX64 | ||
377 | LJ_K32_M2P64_31, /* -2^64 or -2^31 */ | ||
378 | #endif | ||
379 | #if LJ_TARGET_PPC | ||
380 | LJ_K32_2P52_2P31, /* 2^52 + 2^31 */ | ||
381 | LJ_K32_2P52, /* 2^52 */ | ||
382 | #endif | ||
383 | #if LJ_TARGET_PPC || LJ_TARGET_MIPS | ||
384 | LJ_K32_2P31, /* 2^31 */ | ||
385 | #endif | ||
386 | #if LJ_TARGET_MIPS64 | ||
387 | LJ_K32_2P63, /* 2^63 */ | ||
388 | LJ_K32_M2P64, /* -2^64 */ | ||
389 | #endif | ||
390 | LJ_K32__MAX | ||
391 | }; | ||
392 | |||
304 | /* Get 16 byte aligned pointer to SIMD constant. */ | 393 | /* Get 16 byte aligned pointer to SIMD constant. */ |
305 | #define LJ_KSIMD(J, n) \ | 394 | #define LJ_KSIMD(J, n) \ |
306 | ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15)) | 395 | ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15)) |
307 | 396 | ||
308 | /* Set/reset flag to activate the SPLIT pass for the current trace. */ | 397 | /* Set/reset flag to activate the SPLIT pass for the current trace. */ |
309 | #if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) | 398 | #if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI) |
310 | #define lj_needsplit(J) (J->needsplit = 1) | 399 | #define lj_needsplit(J) (J->needsplit = 1) |
311 | #define lj_resetsplit(J) (J->needsplit = 0) | 400 | #define lj_resetsplit(J) (J->needsplit = 0) |
312 | #else | 401 | #else |
@@ -317,13 +406,14 @@ enum { | |||
317 | /* Fold state is used to fold instructions on-the-fly. */ | 406 | /* Fold state is used to fold instructions on-the-fly. */ |
318 | typedef struct FoldState { | 407 | typedef struct FoldState { |
319 | IRIns ins; /* Currently emitted instruction. */ | 408 | IRIns ins; /* Currently emitted instruction. */ |
320 | IRIns left; /* Instruction referenced by left operand. */ | 409 | IRIns left[2]; /* Instruction referenced by left operand. */ |
321 | IRIns right; /* Instruction referenced by right operand. */ | 410 | IRIns right[2]; /* Instruction referenced by right operand. */ |
322 | } FoldState; | 411 | } FoldState; |
323 | 412 | ||
324 | /* JIT compiler state. */ | 413 | /* JIT compiler state. */ |
325 | typedef struct jit_State { | 414 | typedef struct jit_State { |
326 | GCtrace cur; /* Current trace. */ | 415 | GCtrace cur; /* Current trace. */ |
416 | GCtrace *curfinal; /* Final address of current trace (set during asm). */ | ||
327 | 417 | ||
328 | lua_State *L; /* Current Lua state. */ | 418 | lua_State *L; /* Current Lua state. */ |
329 | const BCIns *pc; /* Current PC. */ | 419 | const BCIns *pc; /* Current PC. */ |
@@ -353,8 +443,9 @@ typedef struct jit_State { | |||
353 | int32_t framedepth; /* Current frame depth. */ | 443 | int32_t framedepth; /* Current frame depth. */ |
354 | int32_t retdepth; /* Return frame depth (count of RETF). */ | 444 | int32_t retdepth; /* Return frame depth (count of RETF). */ |
355 | 445 | ||
356 | MRef k64; /* Pointer to chained array of 64 bit constants. */ | 446 | uint32_t k32[LJ_K32__MAX]; /* Common 4 byte constants used by backends. */ |
357 | TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */ | 447 | TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */ |
448 | TValue k64[LJ_K64__MAX]; /* Common 8 byte constants. */ | ||
358 | 449 | ||
359 | IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */ | 450 | IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */ |
360 | IRRef irtoplim; /* Upper limit of instuction buffer (biased). */ | 451 | IRRef irtoplim; /* Upper limit of instuction buffer (biased). */ |
@@ -367,13 +458,15 @@ typedef struct jit_State { | |||
367 | MSize sizesnapmap; /* Size of temp. snapshot map buffer. */ | 458 | MSize sizesnapmap; /* Size of temp. snapshot map buffer. */ |
368 | 459 | ||
369 | PostProc postproc; /* Required post-processing after execution. */ | 460 | PostProc postproc; /* Required post-processing after execution. */ |
370 | #if LJ_SOFTFP || (LJ_32 && LJ_HASFFI) | 461 | #if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI) |
371 | int needsplit; /* Need SPLIT pass. */ | 462 | uint8_t needsplit; /* Need SPLIT pass. */ |
372 | #endif | 463 | #endif |
464 | uint8_t retryrec; /* Retry recording. */ | ||
373 | 465 | ||
374 | GCRef *trace; /* Array of traces. */ | 466 | GCRef *trace; /* Array of traces. */ |
375 | TraceNo freetrace; /* Start of scan for next free trace. */ | 467 | TraceNo freetrace; /* Start of scan for next free trace. */ |
376 | MSize sizetrace; /* Size of trace array. */ | 468 | MSize sizetrace; /* Size of trace array. */ |
469 | IRRef1 ktrace; /* Reference to KGC with GCtrace. */ | ||
377 | 470 | ||
378 | IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */ | 471 | IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */ |
379 | TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */ | 472 | TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */ |
@@ -384,7 +477,10 @@ typedef struct jit_State { | |||
384 | 477 | ||
385 | HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */ | 478 | HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */ |
386 | uint32_t penaltyslot; /* Round-robin index into penalty slots. */ | 479 | uint32_t penaltyslot; /* Round-robin index into penalty slots. */ |
387 | uint32_t prngstate; /* PRNG state. */ | 480 | |
481 | #ifdef LUAJIT_ENABLE_TABLE_BUMP | ||
482 | RBCHashEntry rbchash[RBCHASH_SLOTS]; /* Reverse bytecode map. */ | ||
483 | #endif | ||
388 | 484 | ||
389 | BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ | 485 | BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ |
390 | uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ | 486 | uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ |
@@ -394,6 +490,7 @@ typedef struct jit_State { | |||
394 | const BCIns *startpc; /* Bytecode PC of starting instruction. */ | 490 | const BCIns *startpc; /* Bytecode PC of starting instruction. */ |
395 | TraceNo parent; /* Parent of current side trace (0 for root traces). */ | 491 | TraceNo parent; /* Parent of current side trace (0 for root traces). */ |
396 | ExitNo exitno; /* Exit number in parent of current side trace. */ | 492 | ExitNo exitno; /* Exit number in parent of current side trace. */ |
493 | int exitcode; /* Exit code from unwound trace. */ | ||
397 | 494 | ||
398 | BCIns *patchpc; /* PC for pending re-patch. */ | 495 | BCIns *patchpc; /* PC for pending re-patch. */ |
399 | BCIns patchins; /* Instruction for pending re-patch. */ | 496 | BCIns patchins; /* Instruction for pending re-patch. */ |
@@ -406,14 +503,18 @@ typedef struct jit_State { | |||
406 | size_t szallmcarea; /* Total size of all allocated mcode areas. */ | 503 | size_t szallmcarea; /* Total size of all allocated mcode areas. */ |
407 | 504 | ||
408 | TValue errinfo; /* Additional info element for trace errors. */ | 505 | TValue errinfo; /* Additional info element for trace errors. */ |
506 | |||
507 | #if LJ_HASPROFILE | ||
508 | GCproto *prev_pt; /* Previous prototype. */ | ||
509 | BCLine prev_line; /* Previous line. */ | ||
510 | int prof_mode; /* Profiling mode: 0, 'f', 'l'. */ | ||
511 | #endif | ||
409 | } jit_State; | 512 | } jit_State; |
410 | 513 | ||
411 | /* Trivial PRNG e.g. used for penalty randomization. */ | 514 | #ifdef LUA_USE_ASSERT |
412 | static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits) | 515 | #define lj_assertJ(c, ...) lj_assertG_(J2G(J), (c), __VA_ARGS__) |
413 | { | 516 | #else |
414 | /* Yes, this LCG is very weak, but that doesn't matter for our use case. */ | 517 | #define lj_assertJ(c, ...) ((void)J) |
415 | J->prngstate = J->prngstate * 1103515245 + 12345; | 518 | #endif |
416 | return J->prngstate >> (32-bits); | ||
417 | } | ||
418 | 519 | ||
419 | #endif | 520 | #endif |