diff options
author | Mike Pall <mike> | 2010-03-15 16:23:02 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-03-15 16:23:02 +0100 |
commit | 24402ede0421876b3e681b153c5355e206376799 (patch) | |
tree | 1ba3d5b0c463a8afebfc587161a0a8e8e166f21b /src | |
parent | a25a717089679b629b6f028ede736a52f3c17ade (diff) | |
download | luajit-24402ede0421876b3e681b153c5355e206376799.tar.gz luajit-24402ede0421876b3e681b153c5355e206376799.tar.bz2 luajit-24402ede0421876b3e681b153c5355e206376799.zip |
Reorganize scalar evolution analysis.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_jit.h | 12 | ||||
-rw-r--r-- | src/lj_record.c | 27 |
2 files changed, 32 insertions, 7 deletions
diff --git a/src/lj_jit.h b/src/lj_jit.h index 3201baf0..bd7c7577 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h | |||
@@ -201,6 +201,16 @@ typedef struct BPropEntry { | |||
201 | /* Number of slots for the backpropagation cache. Must be a power of 2. */ | 201 | /* Number of slots for the backpropagation cache. Must be a power of 2. */ |
202 | #define BPROP_SLOTS 16 | 202 | #define BPROP_SLOTS 16 |
203 | 203 | ||
204 | /* Scalar evolution analysis cache. */ | ||
205 | typedef struct ScEvEntry { | ||
206 | IRRef1 idx; /* Index reference. */ | ||
207 | IRRef1 start; /* Constant start reference. */ | ||
208 | IRRef1 stop; /* Constant stop reference. */ | ||
209 | IRRef1 step; /* Constant step reference. */ | ||
210 | IRType1 t; /* Scalar type. */ | ||
211 | uint8_t dir; /* Direction. 0: +, 1: -. */ | ||
212 | } ScEvEntry; | ||
213 | |||
204 | /* 128 bit SIMD constants. */ | 214 | /* 128 bit SIMD constants. */ |
205 | enum { | 215 | enum { |
206 | LJ_KSIMD_ABS, | 216 | LJ_KSIMD_ABS, |
@@ -283,6 +293,8 @@ typedef struct jit_State { | |||
283 | BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ | 293 | BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */ |
284 | uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ | 294 | uint32_t bpropslot; /* Round-robin index into bpropcache slots. */ |
285 | 295 | ||
296 | ScEvEntry scev; /* Scalar evolution analysis cache slots. */ | ||
297 | |||
286 | const BCIns *startpc; /* Bytecode PC of starting instruction. */ | 298 | const BCIns *startpc; /* Bytecode PC of starting instruction. */ |
287 | TraceNo parent; /* Parent of current side trace (0 for root traces). */ | 299 | TraceNo parent; /* Parent of current side trace (0 for root traces). */ |
288 | ExitNo exitno; /* Exit number in parent of current side trace. */ | 300 | ExitNo exitno; /* Exit number in parent of current side trace. */ |
diff --git a/src/lj_record.c b/src/lj_record.c index 44cb7317..0b0768d6 100644 --- a/src/lj_record.c +++ b/src/lj_record.c | |||
@@ -295,9 +295,9 @@ static TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t) | |||
295 | /* Peek before FORI to find a const initializer. Otherwise load from slot. */ | 295 | /* Peek before FORI to find a const initializer. Otherwise load from slot. */ |
296 | static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, IRType t) | 296 | static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot, IRType t) |
297 | { | 297 | { |
298 | TRef tr = find_kinit(J, fori, slot, t); | 298 | TRef tr = J->base[slot]; |
299 | if (!tr) { | 299 | if (!tr) { |
300 | tr = J->base[slot]; | 300 | tr = find_kinit(J, fori, slot, t); |
301 | if (!tr) { | 301 | if (!tr) { |
302 | if (t == IRT_INT) | 302 | if (t == IRT_INT) |
303 | t |= IRT_GUARD; | 303 | t |= IRT_GUARD; |
@@ -347,10 +347,16 @@ static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl) | |||
347 | if (isforl) { /* Handle FORL/JFORL opcodes. */ | 347 | if (isforl) { /* Handle FORL/JFORL opcodes. */ |
348 | TRef step; | 348 | TRef step; |
349 | idx = tr[FORL_IDX]; | 349 | idx = tr[FORL_IDX]; |
350 | if (!idx) idx = sloadt(J, (int32_t)(ra+FORL_IDX), IRT_NUM, 0); | 350 | if (tref_ref(idx) == J->scev.idx) { |
351 | t = tref_type(idx); | 351 | t = J->scev.t.irt; |
352 | stop = fori_arg(J, fori, ra+FORL_STOP, t); | 352 | stop = J->scev.stop; |
353 | step = fori_arg(J, fori, ra+FORL_STEP, t); | 353 | step = J->scev.step; |
354 | } else { | ||
355 | if (!idx) idx = sloadt(J, (int32_t)(ra+FORL_IDX), IRT_NUM, 0); | ||
356 | t = tref_type(idx); | ||
357 | stop = fori_arg(J, fori, ra+FORL_STOP, t); | ||
358 | step = fori_arg(J, fori, ra+FORL_STEP, t); | ||
359 | } | ||
354 | tr[FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step); | 360 | tr[FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step); |
355 | } else { /* Handle FORI/JFORI opcodes. */ | 361 | } else { /* Handle FORI/JFORI opcodes. */ |
356 | BCReg i; | 362 | BCReg i; |
@@ -2258,6 +2264,10 @@ static void rec_setup_forl(jit_State *J, const BCIns *fori) | |||
2258 | TRef step = fori_arg(J, fori, ra+FORL_STEP, t); | 2264 | TRef step = fori_arg(J, fori, ra+FORL_STEP, t); |
2259 | int dir = (0 <= numV(&forbase[FORL_STEP])); | 2265 | int dir = (0 <= numV(&forbase[FORL_STEP])); |
2260 | lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI); | 2266 | lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI); |
2267 | J->scev.t.irt = t; | ||
2268 | J->scev.dir = dir; | ||
2269 | J->scev.stop = tref_ref(stop); | ||
2270 | J->scev.step = tref_ref(step); | ||
2261 | if (!tref_isk(step)) { | 2271 | if (!tref_isk(step)) { |
2262 | /* Non-constant step: need a guard for the direction. */ | 2272 | /* Non-constant step: need a guard for the direction. */ |
2263 | TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J); | 2273 | TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J); |
@@ -2285,9 +2295,11 @@ static void rec_setup_forl(jit_State *J, const BCIns *fori) | |||
2285 | k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k; | 2295 | k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k; |
2286 | emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k)); | 2296 | emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k)); |
2287 | } | 2297 | } |
2288 | if (t == IRT_INT && !find_kinit(J, fori, ra+FORL_IDX, IRT_INT)) | 2298 | J->scev.start = tref_ref(find_kinit(J, fori, ra+FORL_IDX, IRT_INT)); |
2299 | if (t == IRT_INT && !J->scev.start) | ||
2289 | t |= IRT_GUARD; | 2300 | t |= IRT_GUARD; |
2290 | J->base[ra+FORL_EXT] = sloadt(J, (int32_t)(ra+FORL_IDX), t, IRSLOAD_INHERIT); | 2301 | J->base[ra+FORL_EXT] = sloadt(J, (int32_t)(ra+FORL_IDX), t, IRSLOAD_INHERIT); |
2302 | J->scev.idx = tref_ref(J->base[ra+FORL_EXT]); | ||
2291 | J->maxslot = ra+FORL_EXT+1; | 2303 | J->maxslot = ra+FORL_EXT+1; |
2292 | } | 2304 | } |
2293 | 2305 | ||
@@ -2403,6 +2415,7 @@ void lj_record_setup(jit_State *J) | |||
2403 | memset(J->slot, 0, sizeof(J->slot)); | 2415 | memset(J->slot, 0, sizeof(J->slot)); |
2404 | memset(J->chain, 0, sizeof(J->chain)); | 2416 | memset(J->chain, 0, sizeof(J->chain)); |
2405 | memset(J->bpropcache, 0, sizeof(J->bpropcache)); | 2417 | memset(J->bpropcache, 0, sizeof(J->bpropcache)); |
2418 | J->scev.idx = REF_NIL; | ||
2406 | 2419 | ||
2407 | J->baseslot = 1; /* Invoking function is at base[-1]. */ | 2420 | J->baseslot = 1; /* Invoking function is at base[-1]. */ |
2408 | J->base = J->slot + J->baseslot; | 2421 | J->base = J->slot + J->baseslot; |