10000 Add ip_offset back · python/cpython@1a71c1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a71c1a

Browse files
committed
Add ip_offset back
1 parent e529809 commit 1a71c1a

File tree

8 files changed

+15
-13
lines changed

8 files changed

+15
-13
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,6 @@ dummy_func(
30833083
tstate->py_recursion_remaining--;
30843084
LOAD_SP();
30853085
LOAD_IP();
3086-
frame->prev_instr = _PyCode_CODE(_PyFrame_GetCode(frame));
30873086
#if LLTRACE && TIER_ONE
30883087
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
30893088
if (lltrace < 0) {
@@ -3949,7 +3948,7 @@ dummy_func(
39493948
}
39503949

39513950
op(_SET_IP, (--)) {
3952-
frame->prev_instr = (_Py_CODEUNIT *)(uintptr_t)operand;
3951+
frame->prev_instr = ip_offset + oparg;
39533952
}
39543953

39553954
op(_SAVE_CURRENT_IP, (--)) {

Python/ceval_macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ stack_pointer = _PyFrame_GetStackPointer(frame);
393393
#if TIER_TWO
394394

395395
#define LOAD_IP() \
396-
do {} while (0)
396+
do { ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive; } while (0)
397397

398398
#define STORE_SP() \
399399
_PyFrame_SetStackPointer(frame, stack_pointer)

Python/executor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
7171
CHECK_EVAL_BREAKER();
7272

7373
OPT_STAT_INC(traces_executed);
74+
_Py_CODEUNIT *ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
7475
int pc = 0;
7576
int opcode;
7677
int oparg;

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Python/optimizer.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ translate_bytecode_to_trace(
475475
if (trace_stack_depth >= TRACE_STACK_SIZE) { \
476476
DPRINTF(2, "Trace stack overflow\n"); \
477477
OPT_STAT_INC(trace_stack_overflow); \
478+
ADD_TO_TRACE(_SET_IP, 0, 0); \
478479
goto done; \
479480
} \
480481
trace_stack[trace_stack_depth].code = code; \
@@ -497,8 +498,8 @@ translate_bytecode_to_trace(
497498

498499
top: // Jump here after _PUSH_FRAME or likely branches
499500
for (;;) {
500-
RESERVE_RAW(2, "epilogue"); // Always need space for _SET_IP and EXIT_TRACE
501-
ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)instr);
501+
RESERVE_RAW(2, "epilogue"); // Always need space for _SET_IP and _EXIT_TRACE
502+
ADD_TO_TRACE(_SET_IP, INSTR_IP(instr, code), 0);
502503

503504
uint32_t opcode = instr->op.code;
504505
uint32_t oparg = instr->op.arg;
@@ -556,7 +557,7 @@ translate_bytecode_to_trace(
556557
uop_name(opcode), oparg,
557558
counter, bitcount, jump_likely, jump_sense, uop_name(uopcode));
558559
ADD_TO_TRACE(uopcode, max_length, 0);
559-
ADD_TO_STUB(max_length, _SET_IP, 0, (uintptr_t)stub_target);
560+
ADD_TO_STUB(max_length, _SET_IP, INSTR_IP(stub_target, code), 0);
560561
ADD_TO_STUB(max_length + 1, _EXIT_TRACE, 0, 0);
561562
if (jump_likely) {
562563
DPRINTF(2, "Jump likely (%x = %d bits), continue at byte offset %d\n",
@@ -623,7 +624,7 @@ translate_bytecode_to_trace(
623624
ADD_TO_TRACE(next_op, 0, 0);
624625

625626
ADD_TO_STUB(max_length + 0, POP_TOP, 0, 0);
626-
ADD_TO_STUB(max_length + 1, _SET_IP, 0, (uintptr_t)target_instr);
627+
ADD_TO_STUB(max_length + 1, _SET_IP, INSTR_IP(target_instr, code), 0);
627628
ADD_TO_STUB(max_length + 2, _EXIT_TRACE, 0, 0);
628629
break;
629630
}
@@ -679,7 +680,7 @@ translate_bytecode_to_trace(
679680
oparg = orig_oparg & 0xF;
680681
break;
681682
case OPARG_SET_IP: // op==_SET_IP; oparg=next instr
682-
operand = (uintptr_t)(instr + offset);
683+
oparg = INSTR_IP(instr + offset, code);
683684
break;
684685

685686
default:
@@ -719,13 +720,15 @@ translate_bytecode_to_trace(
719720
PyUnicode_AsUTF8(new_code->co_filename),
720721
new_code->co_firstlineno);
721722
OPT_STAT_INC(recursive_call);
723+
ADD_TO_TRACE(_SET_IP, 0, 0);
722724
goto done;
723725
}
724726
if (new_code->co_version != func_version) {
725727
// func.__code__ was updated.
726728
// Perhaps it may happen again, so don't bother tracing.
727729
// TODO: Reason about this -- is it better to bail or not?
728730
DPRINTF(2, "Bailing because co_version != func_version\n");
731+
ADD_TO_TRACE(_SET_IP, 0, 0);
729732
goto done;
730733
}
731734
// Increment IP to the return address
@@ -741,6 +744,7 @@ translate_bytecode_to_trace(
741744
2 * INSTR_IP(instr, code));
742745
goto top;
743746
}
747+
ADD_TO_TRACE(_SET_IP, 0, 0);
744748
goto done;
745749
}
746750
}

Tools/jit/template.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ _JIT_ENTRY(_PyInterpreterFrame *frame, PyObject **stack_pointer,
4747
PyThreadState *tstate, int32_t oparg, uint64_t operand)
4848
{
4949
// Locals that the instruction implementations expect to exist:
50+
_Py_CODEUNIT *ip_offset = _PyCode_CODE(_PyFrame_GetCode(frame));
5051
uint32_t opcode = _JIT_OPCODE;
5152
int pc = -1; // XXX
5253
switch (opcode) {

0 commit comments

Comments
 (0)
0