ljx

FORK: LuaJIT with native 5.2 and 5.3 support
git clone https://git.neptards.moe/neptards/ljx.git
Log | Files | Refs | README

lj_jit.h (17159B)


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