Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 365f7a2

Browse files
committed
Get rid of ip_offset
1 parent e0888de commit 365f7a2

9 files changed

Lines changed: 22 additions & 27 deletions

File tree

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,7 @@ dummy_func(
30063006
tstate->py_recursion_remaining--;
30073007
LOAD_SP();
30083008
LOAD_IP();
3009+
frame->prev_instr = _PyCode_CODE(_PyFrame_GetCode(frame));
30093010
#if LLTRACE && TIER_ONE
30103011
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
30113012
if (lltrace < 0) {
@@ -3794,7 +3795,7 @@ dummy_func(
37943795
}
37953796

37963797
op(SAVE_IP, (--)) {
3797-
frame->prev_instr = ip_offset + oparg;
3798+
frame->prev_instr = (_Py_CODEUNIT *)(uintptr_t)operand;
37983799
}
37993800

38003801
op(SAVE_CURRENT_IP, (--)) {

Python/ceval_macros.h

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

398398
#define LOAD_IP() \
399-
do { ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive; } while (0)
399+
do {} while (0)
400400

401401
#define STORE_SP() \
402402
_PyFrame_SetStackPointer(frame, stack_pointer)

Python/executor.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
6363
CHECK_EVAL_BREAKER();
6464

6565
OBJECT_STAT_INC(optimization_traces_executed);
66-
_Py_CODEUNIT *ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
6766
int pc = 0;
6867
int opcode;
6968
int oparg;

Python/executor_cases.c.h

Lines changed: 2 additions & 1 deletion
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: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ translate_bytecode_to_trace(
481481
#define TRACE_STACK_PUSH() \
482482
if (trace_stack_depth >= TRACE_STACK_SIZE) { \
483483
DPRINTF(2, "Trace stack overflow\n"); \
484-
ADD_TO_TRACE(SAVE_IP, 0, 0); \
485484
goto done; \
486485
} \
487486
trace_stack[trace_stack_depth].code = code; \
@@ -505,7 +504,7 @@ translate_bytecode_to_trace(
505504
top: // Jump here after _PUSH_FRAME
506505
for (;;) {
507506
RESERVE_RAW(2, "epilogue"); // Always need space for SAVE_IP and EXIT_TRACE
508-
ADD_TO_TRACE(SAVE_IP, INSTR_IP(instr, code), 0);
507+
ADD_TO_TRACE(SAVE_IP, 0, (uintptr_t)instr);
509508

510509
uint32_t opcode = instr->op.code;
511510
uint32_t oparg = instr->op.arg;
@@ -556,7 +555,7 @@ translate_bytecode_to_trace(
556555
uint32_t uopcode = opcode == POP_JUMP_IF_TRUE ?
557556
_POP_JUMP_IF_TRUE : _POP_JUMP_IF_FALSE;
558557
ADD_TO_TRACE(uopcode, max_length, 0);
559-
ADD_TO_STUB(max_length, SAVE_IP, INSTR_IP(target_instr, code), 0);
558+
ADD_TO_STUB(max_length, SAVE_IP, 0, (uintptr_t)target_instr);
560559
ADD_TO_STUB(max_length + 1, EXIT_TRACE, 0, 0);
561560
break;
562561
}
@@ -616,7 +615,7 @@ translate_bytecode_to_trace(
616615
ADD_TO_TRACE(next_op, 0, 0);
617616

618617
ADD_TO_STUB(max_length + 0, POP_TOP, 0, 0);
619-
ADD_TO_STUB(max_length + 1, SAVE_IP, INSTR_IP(target_instr, code), 0);
618+
ADD_TO_STUB(max_length + 1, SAVE_IP, 0, (uintptr_t)target_instr);
620619
ADD_TO_STUB(max_length + 2, EXIT_TRACE, 0, 0);
621620
break;
622621
}
@@ -670,7 +669,7 @@ translate_bytecode_to_trace(
670669
oparg = orig_oparg & 0xF;
671670
break;
672671
case OPARG_SAVE_IP: // op==SAVE_IP; oparg=next instr
673-
oparg = INSTR_IP(instr + offset, code);
672+
operand = (uintptr_t)(instr + offset);
674673
break;
675674

676675
default:
@@ -709,15 +708,13 @@ translate_bytecode_to_trace(
709708
PyUnicode_AsUTF8(new_code->co_qualname),
710709
PyUnicode_AsUTF8(new_code->co_filename),
711710
new_code->co_firstlineno);
712-
ADD_TO_TRACE(SAVE_IP, 0, 0);
713711
goto done;
714712
}
715713
if (new_code->co_version != func_version) {
716714
// func.__code__ was updated.
717715
// Perhaps it may happen again, so don't bother tracing.
718716
// TODO: Reason about this -- is it better to bail or not?
719717
DPRINTF(2, "Bailing because co_version != func_version\n");
720-
ADD_TO_TRACE(SAVE_IP, 0, 0);
721718
goto done;
722719
}
723720
// Increment IP to the return address
@@ -733,7 +730,6 @@ translate_bytecode_to_trace(
733730
2 * INSTR_IP(instr, code));
734731
goto top;
735732
}
736-
ADD_TO_TRACE(SAVE_IP, 0, 0);
737733
goto done;
738734
}
739735
}

Tools/jit/template.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,21 @@
3131
// Stuff that will be patched at "JIT time":
3232
extern _PyInterpreterFrame *_jit_branch(_PyInterpreterFrame *frame,
3333
PyObject **stack_pointer,
34-
PyThreadState *tstate,
35-
_Py_CODEUNIT *ip_offset);
34+
PyThreadState *tstate);
3635
extern _PyInterpreterFrame *_jit_continue(_PyInterpreterFrame *frame,
3736
PyObject **stack_pointer,
38-
PyThreadState *tstate,
39-
_Py_CODEUNIT *ip_offset);
37+
PyThreadState *tstate);
4038
extern _PyInterpreterFrame *_jit_loop(_PyInterpreterFrame *frame,
4139
PyObject **stack_pointer,
42-
PyThreadState *tstate,
43-
_Py_CODEUNIT *ip_offset);
40+
PyThreadState *tstate);
4441
// The address of an extern can't be 0:
4542
extern void _jit_oparg_plus_one;
4643
extern void _jit_operand_plus_one;
4744
extern _Py_CODEUNIT _jit_pc_plus_one;
4845

4946
_PyInterpreterFrame *
5047
_jit_entry(_PyInterpreterFrame *frame, PyObject **stack_pointer,
51-
PyThreadState *tstate, _Py_CODEUNIT *ip_offset)
48+
PyThreadState *tstate)
5249
{
5350
// Locals that the instruction implementations expect to exist:
5451
uint32_t opcode = _JIT_OPCODE;
@@ -65,15 +62,15 @@ _jit_entry(_PyInterpreterFrame *frame, PyObject **stack_pointer,
6562
if (opcode == JUMP_TO_TOP) {
6663
assert(pc == 0);
6764
__attribute__((musttail))
68-
return _jit_loop(frame, stack_pointer, tstate, ip_offset);
65+
return _jit_loop(frame, stack_pointer, tstate);
6966
}
7067
if ((opcode == _POP_JUMP_IF_FALSE || opcode == _POP_JUMP_IF_TRUE) && pc != -1) {
7168
assert(pc == oparg);
7269
__attribute__((musttail))
73-
return _jit_branch(frame, stack_pointer, tstate, ip_offset);
70+
return _jit_branch(frame, stack_pointer, tstate);
7471
}
7572
__attribute__((musttail))
76-
return _jit_continue(frame, stack_pointer, tstate, ip_offset);
73+
return _jit_continue(frame, stack_pointer, tstate);
7774
// Labels that the instruction implementations expect to exist:
7875
unbound_local_error:
7976
_PyEval_FormatExcCheckArg(tstate, PyExc_UnboundLocalError,
@@ -94,6 +91,7 @@ _jit_entry(_PyInterpreterFrame *frame, PyObject **stack_pointer,
9491
return NULL;
9592
deoptimize:
9693
frame->prev_instr--;
94+
exit_trace:
9795
_PyFrame_SetStackPointer(frame, stack_pointer);
9896
return frame;
9997
}

Tools/jit/trampoline.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
// Stuff that will be patched at "JIT time":
66
extern _PyInterpreterFrame *_jit_continue(_PyInterpreterFrame *frame,
77
PyObject **stack_pointer,
8-
PyThreadState *tstate,
9-
_Py_CODEUNIT *ip_offset);
8+
PyThreadState *tstate);
109

1110
_PyInterpreterFrame *
1211
_jit_trampoline(_PyExecutorObject *executor, _PyInterpreterFrame *frame,
1312
PyObject **stack_pointer)
1413
{
1514
PyThreadState *tstate = PyThreadState_Get();
16-
_Py_CODEUNIT *ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
17-
frame = _jit_continue(frame, stack_pointer, tstate, ip_offset);
15+
frame = _jit_continue(frame, stack_pointer, tstate);
1816
Py_DECREF(executor);
1917
return frame;
2018
}

0 commit comments

Comments
 (0)