lj_jit.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. ** Common definitions for the JIT compiler.
  3. ** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_JIT_H
  6. #define _LJ_JIT_H
  7. #include "lj_obj.h"
  8. #if LJ_HASJIT
  9. #include "lj_ir.h"
  10. /* -- JIT engine flags ---------------------------------------------------- */
  11. /* General JIT engine flags. 4 bits. */
  12. #define JIT_F_ON 0x00000001
  13. /* CPU-specific JIT engine flags. 12 bits. Flags and strings must match. */
  14. #define JIT_F_CPU 0x00000010
  15. #if LJ_TARGET_X86ORX64
  16. #define JIT_F_SSE3 (JIT_F_CPU << 0)
  17. #define JIT_F_SSE4_1 (JIT_F_CPU << 1)
  18. #define JIT_F_BMI2 (JIT_F_CPU << 2)
  19. #define JIT_F_CPUSTRING "\4SSE3\6SSE4.1\4BMI2"
  20. #elif LJ_TARGET_ARM
  21. #define JIT_F_ARMV6_ (JIT_F_CPU << 0)
  22. #define JIT_F_ARMV6T2_ (JIT_F_CPU << 1)
  23. #define JIT_F_ARMV7 (JIT_F_CPU << 2)
  24. #define JIT_F_ARMV8 (JIT_F_CPU << 3)
  25. #define JIT_F_VFPV2 (JIT_F_CPU << 4)
  26. #define JIT_F_VFPV3 (JIT_F_CPU << 5)
  27. #define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8)
  28. #define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7|JIT_F_ARMV8)
  29. #define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3)
  30. #define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5ARMv8\5VFPv2\5VFPv3"
  31. #elif LJ_TARGET_PPC
  32. #define JIT_F_SQRT (JIT_F_CPU << 0)
  33. #define JIT_F_ROUND (JIT_F_CPU << 1)
  34. #define JIT_F_CPUSTRING "\4SQRT\5ROUND"
  35. #elif LJ_TARGET_MIPS
  36. #define JIT_F_MIPSXXR2 (JIT_F_CPU << 0)
  37. #if LJ_TARGET_MIPS32
  38. #if LJ_TARGET_MIPSR6
  39. #define JIT_F_CPUSTRING "\010MIPS32R6"
  40. #else
  41. #define JIT_F_CPUSTRING "\010MIPS32R2"
  42. #endif
  43. #else
  44. #if LJ_TARGET_MIPSR6
  45. #define JIT_F_CPUSTRING "\010MIPS64R6"
  46. #else
  47. #define JIT_F_CPUSTRING "\010MIPS64R2"
  48. #endif
  49. #endif
  50. #else
  51. #define JIT_F_CPUSTRING ""
  52. #endif
  53. /* Optimization flags. 12 bits. */
  54. #define JIT_F_OPT 0x00010000
  55. #define JIT_F_OPT_MASK 0x0fff0000
  56. #define JIT_F_OPT_FOLD (JIT_F_OPT << 0)
  57. #define JIT_F_OPT_CSE (JIT_F_OPT << 1)
  58. #define JIT_F_OPT_DCE (JIT_F_OPT << 2)
  59. #define JIT_F_OPT_FWD (JIT_F_OPT << 3)
  60. #define JIT_F_OPT_DSE (JIT_F_OPT << 4)
  61. #define JIT_F_OPT_NARROW (JIT_F_OPT << 5)
  62. #define JIT_F_OPT_LOOP (JIT_F_OPT << 6)
  63. #define JIT_F_OPT_ABC (JIT_F_OPT << 7)
  64. #define JIT_F_OPT_SINK (JIT_F_OPT << 8)
  65. #define JIT_F_OPT_FUSE (JIT_F_OPT << 9)
  66. #define JIT_F_OPT_FMA (JIT_F_OPT << 10)
  67. /* Optimizations names for -O. Must match the order above. */
  68. #define JIT_F_OPTSTRING \
  69. "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse\3fma"
  70. /* Optimization levels set a fixed combination of flags. */
  71. #define JIT_F_OPT_0 0
  72. #define JIT_F_OPT_1 (JIT_F_OPT_FOLD|JIT_F_OPT_CSE|JIT_F_OPT_DCE)
  73. #define JIT_F_OPT_2 (JIT_F_OPT_1|JIT_F_OPT_NARROW|JIT_F_OPT_LOOP)
  74. #define JIT_F_OPT_3 (JIT_F_OPT_2|\
  75. JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE)
  76. #define JIT_F_OPT_DEFAULT JIT_F_OPT_3
  77. /* Note: FMA is not set by default. */
  78. /* -- JIT engine parameters ----------------------------------------------- */
  79. #if LJ_TARGET_WINDOWS || LJ_64
  80. /* See: https://devblogs.microsoft.com/oldnewthing/20031008-00/?p=42223 */
  81. #define JIT_P_sizemcode_DEFAULT 64
  82. #else
  83. /* Could go as low as 4K, but the mmap() overhead would be rather high. */
  84. #define JIT_P_sizemcode_DEFAULT 32
  85. #endif
  86. /* Optimization parameters and their defaults. Length is a char in octal! */
  87. #define JIT_PARAMDEF(_) \
  88. _(\010, maxtrace, 1000) /* Max. # of traces in cache. */ \
  89. _(\011, maxrecord, 4000) /* Max. # of recorded IR instructions. */ \
  90. _(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \
  91. _(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \
  92. _(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \
  93. _(\011, minstitch, 0) /* Min. # of IR ins for a stitched trace. */ \
  94. \
  95. _(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \
  96. _(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \
  97. _(\007, tryside, 4) /* # of attempts to compile a side trace. */ \
  98. \
  99. _(\012, instunroll, 4) /* Max. unroll for instable loops. */ \
  100. _(\012, loopunroll, 15) /* Max. unroll for loop ops in side traces. */ \
  101. _(\012, callunroll, 3) /* Max. unroll for recursive calls. */ \
  102. _(\011, recunroll, 2) /* Min. unroll for true recursion. */ \
  103. \
  104. /* Size of each machine code area (in KBytes). */ \
  105. _(\011, sizemcode, JIT_P_sizemcode_DEFAULT) \
  106. /* Max. total size of all machine code areas (in KBytes). */ \
  107. _(\010, maxmcode, 512) \
  108. /* End of list. */
  109. enum {
  110. #define JIT_PARAMENUM(len, name, value) JIT_P_##name,
  111. JIT_PARAMDEF(JIT_PARAMENUM)
  112. #undef JIT_PARAMENUM
  113. JIT_P__MAX
  114. };
  115. #define JIT_PARAMSTR(len, name, value) #len #name
  116. #define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR)
  117. /* -- JIT engine data structures ------------------------------------------ */
  118. /* Trace compiler state. */
  119. typedef enum {
  120. LJ_TRACE_IDLE, /* Trace compiler idle. */
  121. LJ_TRACE_ACTIVE = 0x10,
  122. LJ_TRACE_RECORD, /* Bytecode recording active. */
  123. LJ_TRACE_RECORD_1ST, /* Record 1st instruction, too. */
  124. LJ_TRACE_START, /* New trace started. */
  125. LJ_TRACE_END, /* End of trace. */
  126. LJ_TRACE_ASM, /* Assemble trace. */
  127. LJ_TRACE_ERR /* Trace aborted with error. */
  128. } TraceState;
  129. /* Post-processing action. */
  130. typedef enum {
  131. LJ_POST_NONE, /* No action. */
  132. LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */
  133. LJ_POST_FIXGUARD, /* Fixup and emit pending guard. */
  134. LJ_POST_FIXGUARDSNAP, /* Fixup and emit pending guard and snapshot. */
  135. LJ_POST_FIXBOOL, /* Fixup boolean result. */
  136. LJ_POST_FIXCONST, /* Fixup constant results. */
  137. LJ_POST_FFRETRY /* Suppress recording of retried fast functions. */
  138. } PostProc;
  139. /* Machine code type. */
  140. #if LJ_TARGET_X86ORX64
  141. typedef uint8_t MCode;
  142. #else
  143. typedef uint32_t MCode;
  144. #endif
  145. /* Linked list of MCode areas. */
  146. typedef struct MCLink {
  147. MCode *next; /* Next area. */
  148. size_t size; /* Size of current area. */
  149. } MCLink;
  150. /* Stack snapshot header. */
  151. typedef struct SnapShot {
  152. uint32_t mapofs; /* Offset into snapshot map. */
  153. IRRef1 ref; /* First IR ref for this snapshot. */
  154. uint16_t mcofs; /* Offset into machine code in MCode units. */
  155. uint8_t nslots; /* Number of valid slots. */
  156. uint8_t topslot; /* Maximum frame extent. */
  157. uint8_t nent; /* Number of compressed entries. */
  158. uint8_t count; /* Count of taken exits for this snapshot. */
  159. } SnapShot;
  160. #define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */
  161. /* Compressed snapshot entry. */
  162. typedef uint32_t SnapEntry;
  163. #define SNAP_FRAME 0x010000 /* Frame slot. */
  164. #define SNAP_CONT 0x020000 /* Continuation slot. */
  165. #define SNAP_NORESTORE 0x040000 /* No need to restore slot. */
  166. #define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */
  167. #define SNAP_KEYINDEX 0x100000 /* Traversal key index. */
  168. LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME);
  169. LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT);
  170. LJ_STATIC_ASSERT(SNAP_KEYINDEX == TREF_KEYINDEX);
  171. #define SNAP(slot, flags, ref) (((SnapEntry)(slot) << 24) + (flags) + (ref))
  172. #define SNAP_TR(slot, tr) \
  173. (((SnapEntry)(slot) << 24) + \
  174. ((tr) & (TREF_KEYINDEX|TREF_CONT|TREF_FRAME|TREF_REFMASK)))
  175. #if !LJ_FR2
  176. #define SNAP_MKPC(pc) ((SnapEntry)u32ptr(pc))
  177. #endif
  178. #define SNAP_MKFTSZ(ftsz) ((SnapEntry)(ftsz))
  179. #define snap_ref(sn) ((sn) & 0xffff)
  180. #define snap_slot(sn) ((BCReg)((sn) >> 24))
  181. #define snap_isframe(sn) ((sn) & SNAP_FRAME)
  182. #define snap_setref(sn, ref) (((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref))
  183. static LJ_AINLINE const BCIns *snap_pc(SnapEntry *sn)
  184. {
  185. #if LJ_FR2
  186. uint64_t pcbase;
  187. memcpy(&pcbase, sn, sizeof(uint64_t));
  188. return (const BCIns *)(pcbase >> 8);
  189. #else
  190. return (const BCIns *)(uintptr_t)*sn;
  191. #endif
  192. }
  193. /* Snapshot and exit numbers. */
  194. typedef uint32_t SnapNo;
  195. typedef uint32_t ExitNo;
  196. /* Trace number. */
  197. typedef uint32_t TraceNo; /* Used to pass around trace numbers. */
  198. typedef uint16_t TraceNo1; /* Stored trace number. */
  199. /* Type of link. ORDER LJ_TRLINK */
  200. typedef enum {
  201. LJ_TRLINK_NONE, /* Incomplete trace. No link, yet. */
  202. LJ_TRLINK_ROOT, /* Link to other root trace. */
  203. LJ_TRLINK_LOOP, /* Loop to same trace. */
  204. LJ_TRLINK_TAILREC, /* Tail-recursion. */
  205. LJ_TRLINK_UPREC, /* Up-recursion. */
  206. LJ_TRLINK_DOWNREC, /* Down-recursion. */
  207. LJ_TRLINK_INTERP, /* Fallback to interpreter. */
  208. LJ_TRLINK_RETURN, /* Return to interpreter. */
  209. LJ_TRLINK_STITCH /* Trace stitching. */
  210. } TraceLink;
  211. /* Trace object. */
  212. typedef struct GCtrace {
  213. GCHeader;
  214. uint16_t nsnap; /* Number of snapshots. */
  215. IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */
  216. #if LJ_GC64
  217. uint32_t unused_gc64;
  218. #endif
  219. GCRef gclist;
  220. IRIns *ir; /* IR instructions/constants. Biased with REF_BIAS. */
  221. IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */
  222. uint32_t nsnapmap; /* Number of snapshot map elements. */
  223. SnapShot *snap; /* Snapshot array. */
  224. SnapEntry *snapmap; /* Snapshot map. */
  225. GCRef startpt; /* Starting prototype. */
  226. MRef startpc; /* Bytecode PC of starting instruction. */
  227. BCIns startins; /* Original bytecode of starting instruction. */
  228. MSize szmcode; /* Size of machine code. */
  229. MCode *mcode; /* Start of machine code. */
  230. #if LJ_ABI_PAUTH
  231. ASMFunction mcauth; /* Start of machine code, with ptr auth applied. */
  232. #endif
  233. MSize mcloop; /* Offset of loop start in machine code. */
  234. uint16_t nchild; /* Number of child traces (root trace only). */
  235. uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */
  236. TraceNo1 traceno; /* Trace number. */
  237. TraceNo1 link; /* Linked trace (or self for loops). */
  238. TraceNo1 root; /* Root trace of side trace (or 0 for root traces). */
  239. TraceNo1 nextroot; /* Next root trace for same prototype. */
  240. TraceNo1 nextside; /* Next side trace of same root trace. */
  241. uint8_t sinktags; /* Trace has SINK tags. */
  242. uint8_t topslot; /* Top stack slot already checked to be allocated. */
  243. uint8_t linktype; /* Type of link. */
  244. uint8_t unused1;
  245. #ifdef LUAJIT_USE_GDBJIT
  246. void *gdbjit_entry; /* GDB JIT entry. */
  247. #endif
  248. } GCtrace;
  249. #define gco2trace(o) check_exp((o)->gch.gct == ~LJ_TTRACE, (GCtrace *)(o))
  250. #define traceref(J, n) \
  251. check_exp((n)>0 && (MSize)(n)<J->sizetrace, (GCtrace *)gcref(J->trace[(n)]))
  252. LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist));
  253. static LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap)
  254. {
  255. if (snap+1 == &T->snap[T->nsnap])
  256. return T->nsnapmap;
  257. else
  258. return (snap+1)->mapofs;
  259. }
  260. /* Round-robin penalty cache for bytecodes leading to aborted traces. */
  261. typedef struct HotPenalty {
  262. MRef pc; /* Starting bytecode PC. */
  263. uint16_t val; /* Penalty value, i.e. hotcount start. */
  264. uint16_t reason; /* Abort reason (really TraceErr). */
  265. } HotPenalty;
  266. #define PENALTY_SLOTS 64 /* Penalty cache slot. Must be a power of 2. */
  267. #define PENALTY_MIN (36*2) /* Minimum penalty value. */
  268. #define PENALTY_MAX 60000 /* Maximum penalty value. */
  269. #define PENALTY_RNDBITS 4 /* # of random bits to add to penalty value. */
  270. /* Round-robin backpropagation cache for narrowing conversions. */
  271. typedef struct BPropEntry {
  272. IRRef1 key; /* Key: original reference. */
  273. IRRef1 val; /* Value: reference after conversion. */
  274. IRRef mode; /* Mode for this entry (currently IRCONV_*). */
  275. } BPropEntry;
  276. /* Number of slots for the backpropagation cache. Must be a power of 2. */
  277. #define BPROP_SLOTS 16
  278. /* Scalar evolution analysis cache. */
  279. typedef struct ScEvEntry {
  280. MRef pc; /* Bytecode PC of FORI. */
  281. IRRef1 idx; /* Index reference. */
  282. IRRef1 start; /* Constant start reference. */
  283. IRRef1 stop; /* Constant stop reference. */
  284. IRRef1 step; /* Constant step reference. */
  285. IRType1 t; /* Scalar type. */
  286. uint8_t dir; /* Direction. 1: +, 0: -. */
  287. } ScEvEntry;
  288. /* Reverse bytecode map (IRRef -> PC). Only for selected instructions. */
  289. typedef struct RBCHashEntry {
  290. MRef pc; /* Bytecode PC. */
  291. GCRef pt; /* Prototype. */
  292. IRRef ref; /* IR reference. */
  293. } RBCHashEntry;
  294. /* Number of slots in the reverse bytecode hash table. Must be a power of 2. */
  295. #define RBCHASH_SLOTS 8
  296. /* 128 bit SIMD constants. */
  297. enum {
  298. LJ_KSIMD_ABS,
  299. LJ_KSIMD_NEG,
  300. LJ_KSIMD__MAX
  301. };
  302. enum {
  303. #if LJ_TARGET_X86ORX64
  304. LJ_K64_TOBIT, /* 2^52 + 2^51 */
  305. LJ_K64_2P64, /* 2^64 */
  306. LJ_K64_M2P64, /* -2^64 */
  307. #if LJ_32
  308. LJ_K64_M2P64_31, /* -2^64 or -2^31 */
  309. #else
  310. LJ_K64_M2P64_31 = LJ_K64_M2P64,
  311. #endif
  312. #endif
  313. #if LJ_TARGET_MIPS
  314. LJ_K64_2P31, /* 2^31 */
  315. #if LJ_64
  316. LJ_K64_2P63, /* 2^63 */
  317. LJ_K64_M2P64, /* -2^64 */
  318. #endif
  319. #endif
  320. LJ_K64__MAX,
  321. };
  322. #define LJ_K64__USED (LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS)
  323. enum {
  324. #if LJ_TARGET_X86ORX64
  325. LJ_K32_M2P64_31, /* -2^64 or -2^31 */
  326. #endif
  327. #if LJ_TARGET_PPC
  328. LJ_K32_2P52_2P31, /* 2^52 + 2^31 */
  329. LJ_K32_2P52, /* 2^52 */
  330. #endif
  331. #if LJ_TARGET_PPC || LJ_TARGET_MIPS
  332. LJ_K32_2P31, /* 2^31 */
  333. #endif
  334. #if LJ_TARGET_MIPS64
  335. LJ_K32_2P63, /* 2^63 */
  336. LJ_K32_M2P64, /* -2^64 */
  337. #endif
  338. LJ_K32__MAX
  339. };
  340. #define LJ_K32__USED (LJ_TARGET_X86ORX64 || LJ_TARGET_PPC || LJ_TARGET_MIPS)
  341. /* Get 16 byte aligned pointer to SIMD constant. */
  342. #define LJ_KSIMD(J, n) \
  343. ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15))
  344. /* Set/reset flag to activate the SPLIT pass for the current trace. */
  345. #if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)
  346. #define lj_needsplit(J) (J->needsplit = 1)
  347. #define lj_resetsplit(J) (J->needsplit = 0)
  348. #else
  349. #define lj_needsplit(J) UNUSED(J)
  350. #define lj_resetsplit(J) UNUSED(J)
  351. #endif
  352. /* Fold state is used to fold instructions on-the-fly. */
  353. typedef struct FoldState {
  354. IRIns ins; /* Currently emitted instruction. */
  355. IRIns left[2]; /* Instruction referenced by left operand. */
  356. IRIns right[2]; /* Instruction referenced by right operand. */
  357. } FoldState;
  358. /* JIT compiler state. */
  359. typedef struct jit_State {
  360. GCtrace cur; /* Current trace. */
  361. GCtrace *curfinal; /* Final address of current trace (set during asm). */
  362. lua_State *L; /* Current Lua state. */
  363. const BCIns *pc; /* Current PC. */
  364. GCfunc *fn; /* Current function. */
  365. GCproto *pt; /* Current prototype. */
  366. TRef *base; /* Current frame base, points into J->slots. */
  367. uint32_t flags; /* JIT engine flags. */
  368. BCReg maxslot; /* Relative to baseslot. */
  369. BCReg baseslot; /* Current frame base, offset into J->slots. */
  370. uint8_t mergesnap; /* Allowed to merge with next snapshot. */
  371. uint8_t needsnap; /* Need snapshot before recording next bytecode. */
  372. IRType1 guardemit; /* Accumulated IRT_GUARD for emitted instructions. */
  373. uint8_t bcskip; /* Number of bytecode instructions to skip. */
  374. FoldState fold; /* Fold state. */
  375. const BCIns *bc_min; /* Start of allowed bytecode range for root trace. */
  376. MSize bc_extent; /* Extent of the range. */
  377. TraceState state; /* Trace compiler state. */
  378. int32_t instunroll; /* Unroll counter for instable loops. */
  379. int32_t loopunroll; /* Unroll counter for loop ops in side traces. */
  380. int32_t tailcalled; /* Number of successive tailcalls. */
  381. int32_t framedepth; /* Current frame depth. */
  382. int32_t retdepth; /* Return frame depth (count of RETF). */
  383. #if LJ_K32__USED
  384. uint32_t k32[LJ_K32__MAX]; /* Common 4 byte constants used by backends. */
  385. #endif
  386. TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */
  387. #if LJ_K64__USED
  388. TValue k64[LJ_K64__MAX]; /* Common 8 byte constants. */
  389. #endif
  390. IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */
  391. IRRef irtoplim; /* Upper limit of instuction buffer (biased). */
  392. IRRef irbotlim; /* Lower limit of instuction buffer (biased). */
  393. IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */
  394. MSize sizesnap; /* Size of temp. snapshot buffer. */
  395. SnapShot *snapbuf; /* Temp. snapshot buffer. */
  396. SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */
  397. MSize sizesnapmap; /* Size of temp. snapshot map buffer. */
  398. PostProc postproc; /* Required post-processing after execution. */
  399. #if LJ_SOFTFP32 || (LJ_32 && LJ_HASFFI)
  400. uint8_t needsplit; /* Need SPLIT pass. */
  401. #endif
  402. uint8_t retryrec; /* Retry recording. */
  403. GCRef *trace; /* Array of traces. */
  404. TraceNo freetrace; /* Start of scan for next free trace. */
  405. MSize sizetrace; /* Size of trace array. */
  406. IRRef1 ktrace; /* Reference to KGC with GCtrace. */
  407. IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */
  408. TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */
  409. int32_t param[JIT_P__MAX]; /* JIT engine parameters. */
  410. MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */
  411. HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */
  412. uint32_t penaltyslot; /* Round-robin index into penalty slots. */
  413. #ifdef LUAJIT_ENABLE_TABLE_BUMP
  414. RBCHashEntry rbchash[RBCHASH_SLOTS]; /* Reverse bytecode map. */
  415. #endif
  416. BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */
  417. uint32_t bpropslot; /* Round-robin index into bpropcache slots. */
  418. ScEvEntry scev; /* Scalar evolution analysis cache slots. */
  419. const BCIns *startpc; /* Bytecode PC of starting instruction. */
  420. TraceNo parent; /* Parent of current side trace (0 for root traces). */
  421. ExitNo exitno; /* Exit number in parent of current side trace. */
  422. int exitcode; /* Exit code from unwound trace. */
  423. BCIns *patchpc; /* PC for pending re-patch. */
  424. BCIns patchins; /* Instruction for pending re-patch. */
  425. int mcprot; /* Protection of current mcode area. */
  426. MCode *mcarea; /* Base of current mcode area. */
  427. MCode *mctop; /* Top of current mcode area. */
  428. MCode *mcbot; /* Bottom of current mcode area. */
  429. size_t szmcarea; /* Size of current mcode area. */
  430. size_t szallmcarea; /* Total size of all allocated mcode areas. */
  431. TValue errinfo; /* Additional info element for trace errors. */
  432. #if LJ_HASPROFILE
  433. GCproto *prev_pt; /* Previous prototype. */
  434. BCLine prev_line; /* Previous line. */
  435. int prof_mode; /* Profiling mode: 0, 'f', 'l'. */
  436. #endif
  437. } jit_State;
  438. #ifdef LUA_USE_ASSERT
  439. #define lj_assertJ(c, ...) lj_assertG_(J2G(J), (c), __VA_ARGS__)
  440. #else
  441. #define lj_assertJ(c, ...) ((void)J)
  442. #endif
  443. #endif
  444. #endif