Skip to content

Commit fe3a6a1

Browse files
massive refactoring 2
1 parent 4aeb4ab commit fe3a6a1

File tree

7 files changed

+95
-93
lines changed

7 files changed

+95
-93
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -768,18 +768,20 @@ typedef struct _PyJitTracerState {
768768
_Py_CODEUNIT *close_loop_instr;
769769
_Py_CODEUNIT *jump_backward_instr;
770770
} initial_state;
771-
bool dependencies_still_valid;
772-
bool prev_instr_is_super;
773-
int code_max_size;
774-
int code_curr_size;
775-
int prev_instr_oparg;
776-
int prev_instr_stacklevel;
777-
int specialize_counter;
778771
_PyUOpInstruction *code_buffer;
779-
_Py_CODEUNIT *prev_instr;
780-
PyCodeObject *prev_instr_code; // Strong
781-
_PyInterpreterFrame *prev_instr_frame;
782-
_PyBloomFilter dependencies;
772+
struct {
773+
bool dependencies_still_valid;
774+
bool instr_is_super;
775+
int code_max_size;
776+
int code_curr_size;
777+
int instr_oparg;
778+
int instr_stacklevel;
779+
int specialize_counter;
780+
_Py_CODEUNIT *instr;
781+
PyCodeObject *instr_code; // Strong
782+
_PyInterpreterFrame *instr_frame;
783+
_PyBloomFilter dependencies;
784+
} prev_state;;
783785
} _PyJitTracerState;
784786

785787
/* PyInterpreterState holds the global state for one of the runtime's

Python/bytecodes.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5673,24 +5673,24 @@ dummy_func(
56735673
}
56745674
// Super instructions. Instruction deopted. There's a mismatch in what the stack expects
56755675
// in the optimizer. So we have to reflect in the trace correctly.
5676-
if ((tstate->interp->jit_state.prev_instr->op.code == CALL_LIST_APPEND &&
5676+
if ((tstate->interp->jit_state.prev_state.instr->op.code == CALL_LIST_APPEND &&
56775677
opcode == POP_TOP) ||
5678-
(tstate->interp->jit_state.prev_instr->op.code == BINARY_OP_INPLACE_ADD_UNICODE &&
5678+
(tstate->interp->jit_state.prev_state.instr->op.code == BINARY_OP_INPLACE_ADD_UNICODE &&
56795679
opcode == STORE_FAST)) {
5680-
tstate->interp->jit_state.prev_instr_is_super = true;
5680+
tstate->interp->jit_state.prev_state.instr_is_super = true;
56815681
}
56825682
else {
5683-
tstate->interp->jit_state.prev_instr = next_instr;
5683+
tstate->interp->jit_state.prev_state.instr = next_instr;
56845684
}
5685-
tstate->interp->jit_state.specialize_counter = 0;
5685+
tstate->interp->jit_state.prev_state.specialize_counter = 0;
56865686
PyCodeObject *prev_code = (PyCodeObject *)Py_NewRef(PyStackRef_AsPyObjectBorrow(frame->f_executable));
5687-
if (tstate->interp->jit_state.prev_instr_code != prev_code) {
5688-
Py_SETREF(tstate->interp->jit_state.prev_instr_code, prev_code);
5687+
if (tstate->interp->jit_state.prev_state.instr_code != prev_code) {
5688+
Py_SETREF(tstate->interp->jit_state.prev_state.instr_code, prev_code);
56895689
}
56905690

5691-
tstate->interp->jit_state.prev_instr_frame = frame;
5692-
tstate->interp->jit_state.prev_instr_oparg = oparg;
5693-
tstate->interp->jit_state.prev_instr_stacklevel = PyStackRef_IsNone(frame->f_executable) ? 2 : STACK_LEVEL();
5691+
tstate->interp->jit_state.prev_state.instr_frame = frame;
5692+
tstate->interp->jit_state.prev_state.instr_oparg = oparg;
5693+
tstate->interp->jit_state.prev_state.instr_stacklevel = PyStackRef_IsNone(frame->f_executable) ? 2 : STACK_LEVEL();
56945694
DISPATCH_GOTO_NON_TRACING();
56955695
#else
56965696
Py_FatalError("JIT label executed in non-jit build.");

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ bail_tracing_and_jit(PyThreadState *tstate, _PyInterpreterFrame *frame)
10171017
// to be valid to access.
10181018
if (err <= 0) {
10191019
// Some opcodes will forever be unchanged. Don't ever bother specializing for them ever again.
1020-
if (tstate->interp->jit_state.prev_instr->op.code == INTERPRETER_EXIT) {
1020+
if (tstate->interp->jit_state.prev_state.instr->op.code == INTERPRETER_EXIT) {
10211021
exit->temperature = initial_unreachable_backoff_counter();
10221022
}
10231023
else {

Python/ceval_macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134

135135
#if (_Py_TAIL_CALL_INTERP || USE_COMPUTED_GOTOS) && _Py_TIER2
136136
# define IS_JIT_TRACING() (DISPATCH_TABLE_VAR == TRACING_DISPATCH_TABLE)
137-
# define IS_JIT_TRACING_MAKING_PROGRESS() (IS_JIT_TRACING() && tstate->interp->jit_state.specialize_counter < MAX_SPECIALIZATION_TRIES)
137+
# define IS_JIT_TRACING_MAKING_PROGRESS() (IS_JIT_TRACING() && tstate->interp->jit_state.prev_state.specialize_counter < MAX_SPECIALIZATION_TRIES)
138138
# define ENTER_TRACING() \
139139
DISPATCH_TABLE_VAR = TRACING_DISPATCH_TABLE;
140140
# define LEAVE_TRACING() \
@@ -402,7 +402,7 @@ do { \
402402
JUMP_TO_LABEL(error); \
403403
} \
404404
if (keep_tracing_bit) { \
405-
assert(tstate->interp->jit_state.code_curr_size == 2 || tstate->interp->jit_state.code_curr_size == 3); \
405+
assert(tstate->interp->jit_state.prev_state.code_curr_size == 2); \
406406
ENTER_TRACING(); \
407407
DISPATCH_NON_TRACING(); \
408408
} \

Python/generated_cases.c.h

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)