Skip to content

Commit a5d918e

Browse files
Change RECORD_PREVIOUS_INST to a label to save an opcode
1 parent 4b4e857 commit a5d918e

File tree

10 files changed

+573
-605
lines changed

10 files changed

+573
-605
lines changed

Include/internal/pycore_magic_number.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ Known values:
286286
Python 3.15a1 3653 (Fix handling of opcodes that may leave operands on the stack when optimizing LOAD_FAST)
287287
Python 3.15a1 3654 (Fix missing exception handlers in logical expression)
288288
Python 3.15a1 3655 (Fix miscompilation of some module-level annotations)
289-
Python 3.15a2 3656 (Add RECORD_PREVIOUS_INST for a tracing JIT)
290289
291290
292291
Python 3.16 will start with 3700
@@ -300,7 +299,7 @@ PC/launcher.c must also be updated.
300299
301300
*/
302301

303-
#define PYC_MAGIC_NUMBER 3656
302+
#define PYC_MAGIC_NUMBER 3655
304303
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
305304
(little-endian) and then appending b'\r\n'. */
306305
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

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

Include/opcode_ids.h

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

Lib/_opcode_metadata.py

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

Programs/test_frozenmain.h

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

Python/bytecodes.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5193,40 +5193,6 @@ dummy_func(
51935193
Py_FatalError("Executing RESERVED instruction.");
51945194
}
51955195

5196-
tier1 no_save_ip inst(RECORD_PREVIOUS_INST, (--)) {
5197-
#if _Py_TIER2
5198-
assert(IS_JIT_TRACING());
5199-
int opcode = next_instr->op.code;
5200-
int full = !_PyJit_translate_single_bytecode_to_trace(tstate, frame, next_instr);
5201-
if (full) {
5202-
LEAVE_TRACING();
5203-
int err = bail_tracing_and_jit(tstate, frame);
5204-
ERROR_IF(err < 0);
5205-
DISPATCH_GOTO_NON_TRACING();
5206-
}
5207-
// Super instructions. Instruction deopted. There's a mismatch in what the stack expects
5208-
// in the optimizer. So we have to reflect in the trace correctly.
5209-
if ((tstate->interp->jit_state.prev_instr->op.code == CALL_LIST_APPEND &&
5210-
opcode == POP_TOP) ||
5211-
(tstate->interp->jit_state.prev_instr->op.code == BINARY_OP_INPLACE_ADD_UNICODE &&
5212-
opcode == STORE_FAST)) {
5213-
tstate->interp->jit_state.prev_instr_is_super = true;
5214-
}
5215-
else {
5216-
tstate->interp->jit_state.prev_instr = next_instr;
5217-
}
5218-
tstate->interp->jit_state.specialize_counter = 0;
5219-
PyCodeObject *prev_code = (PyCodeObject *)Py_NewRef(_PyFrame_GetCode(frame));
5220-
Py_SETREF(tstate->interp->jit_state.prev_instr_code, prev_code);
5221-
5222-
tstate->interp->jit_state.prev_instr_frame = frame;
5223-
tstate->interp->jit_state.prev_instr_oparg = oparg;
5224-
tstate->interp->jit_state.prev_instr_stacklevel = STACK_LEVEL();
5225-
DISPATCH_GOTO_NON_TRACING();
5226-
#else
5227-
Py_FatalError("JIT instruction executed in non-jit build.");
5228-
#endif
5229-
}
52305196
///////// Tier-2 only opcodes /////////
52315197

52325198
op (_GUARD_IS_TRUE_POP, (flag -- )) {
@@ -5646,6 +5612,40 @@ dummy_func(
56465612
DISPATCH();
56475613
}
56485614

5615+
label(record_previous_inst) {
5616+
#if _Py_TIER2
5617+
assert(IS_JIT_TRACING());
5618+
int opcode = next_instr->op.code;
5619+
int full = !_PyJit_translate_single_bytecode_to_trace(tstate, frame, next_instr);
5620+
if (full) {
5621+
LEAVE_TRACING();
5622+
int err = bail_tracing_and_jit(tstate, frame);
5623+
ERROR_IF(err < 0);
5624+
DISPATCH_GOTO_NON_TRACING();
5625+
}
5626+
// Super instructions. Instruction deopted. There's a mismatch in what the stack expects
5627+
// in the optimizer. So we have to reflect in the trace correctly.
5628+
if ((tstate->interp->jit_state.prev_instr->op.code == CALL_LIST_APPEND &&
5629+
opcode == POP_TOP) ||
5630+
(tstate->interp->jit_state.prev_instr->op.code == BINARY_OP_INPLACE_ADD_UNICODE &&
5631+
opcode == STORE_FAST)) {
5632+
tstate->interp->jit_state.prev_instr_is_super = true;
5633+
}
5634+
else {
5635+
tstate->interp->jit_state.prev_instr = next_instr;
5636+
}
5637+
tstate->interp->jit_state.specialize_counter = 0;
5638+
PyCodeObject *prev_code = (PyCodeObject *)Py_NewRef(_PyFrame_GetCode(frame));
5639+
Py_SETREF(tstate->interp->jit_state.prev_instr_code, prev_code);
5640+
5641+
tstate->interp->jit_state.prev_instr_frame = frame;
5642+
tstate->interp->jit_state.prev_instr_oparg = oparg;
5643+
tstate->interp->jit_state.prev_instr_stacklevel = STACK_LEVEL();
5644+
DISPATCH_GOTO_NON_TRACING();
5645+
#else
5646+
Py_FatalError("JIT label executed in non-jit build.");
5647+
#endif
5648+
}
56495649

56505650

56515651
// END BYTECODES //

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)