summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-11-17 19:36:03 (GMT)
committerGitHub <noreply@github.com>2022-11-17 19:36:03 (GMT)
commit6f8b0e781ccd5d17f00f91d1c4eddba4f3e9a8ed (patch)
treea764c8b2012cbd9df6cb014edd21c88b66d43a4a /Python/bytecodes.c
parenta0d940d6acbb5c6614cf892192d8cb0d7002e5a6 (diff)
downloadcpython-6f8b0e781ccd5d17f00f91d1c4eddba4f3e9a8ed.zip
cpython-6f8b0e781ccd5d17f00f91d1c4eddba4f3e9a8ed.tar.gz
cpython-6f8b0e781ccd5d17f00f91d1c4eddba4f3e9a8ed.tar.bz2
Add a macro for "inlining" new frames (GH-99490)
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c52
1 files changed, 9 insertions, 43 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 1575b53..0b2c9e8 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -467,13 +467,8 @@ dummy_func(
for (int i = 2; i < code->co_nlocalsplus; i++) {
new_frame->localsplus[i] = NULL;
}
- _PyFrame_SetStackPointer(frame, stack_pointer);
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
- frame->prev_instr = next_instr - 1;
- new_frame->previous = frame;
- frame = cframe.current_frame = new_frame;
- CALL_STAT_INC(inlined_py_calls);
- goto start_frame;
+ DISPATCH_INLINED(new_frame);
}
// stack effect: (__0 -- )
@@ -1938,13 +1933,8 @@ dummy_func(
for (int i = 1; i < code->co_nlocalsplus; i++) {
new_frame->localsplus[i] = NULL;
}
- _PyFrame_SetStackPointer(frame, stack_pointer);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
- frame->prev_instr = next_instr - 1;
- new_frame->previous = frame;
- frame = cframe.current_frame = new_frame;
- CALL_STAT_INC(inlined_py_calls);
- goto start_frame;
+ DISPATCH_INLINED(new_frame);
}
// error: LOAD_ATTR has irregular stack effect
@@ -1979,13 +1969,8 @@ dummy_func(
for (int i = 2; i < code->co_nlocalsplus; i++) {
new_frame->localsplus[i] = NULL;
}
- _PyFrame_SetStackPointer(frame, stack_pointer);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
- frame->prev_instr = next_instr - 1;
- new_frame->previous = frame;
- frame = cframe.current_frame = new_frame;
- CALL_STAT_INC(inlined_py_calls);
- goto start_frame;
+ DISPATCH_INLINED(new_frame);
}
// stack effect: (__0, __1 -- )
@@ -2685,18 +2670,14 @@ dummy_func(
DEOPT_IF(gen->gi_frame_state >= FRAME_EXECUTING, FOR_ITER);
STAT_INC(FOR_ITER, hit);
_PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
- _PyFrame_SetStackPointer(frame, stack_pointer);
frame->yield_offset = oparg;
- JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
- assert(_Py_OPCODE(*next_instr) == END_FOR);
- frame->prev_instr = next_instr - 1;
_PyFrame_StackPush(gen_frame, Py_NewRef(Py_None));
gen->gi_frame_state = FRAME_EXECUTING;
gen->gi_exc_state.previous_item = tstate->exc_info;
tstate->exc_info = &gen->gi_exc_state;
- gen_frame->previous = frame;
- frame = cframe.current_frame = gen_frame;
- goto start_frame;
+ JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
+ assert(_Py_OPCODE(*next_instr) == END_FOR);
+ DISPATCH_INLINED(gen_frame);
}
// stack effect: ( -- __0)
@@ -2978,13 +2959,8 @@ dummy_func(
if (new_frame == NULL) {
goto error;
}
- _PyFrame_SetStackPointer(frame, stack_pointer);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
- frame->prev_instr = next_instr - 1;
- new_frame->previous = frame;
- cframe.current_frame = frame = new_frame;
- CALL_STAT_INC(inlined_py_calls);
- goto start_frame;
+ DISPATCH_INLINED(new_frame);
}
/* Callable is not a normal Python function */
PyObject *res;
@@ -3032,7 +3008,6 @@ dummy_func(
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
STAT_INC(CALL, hit);
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
- CALL_STAT_INC(inlined_py_calls);
STACK_SHRINK(argcount);
for (int i = 0; i < argcount; i++) {
new_frame->localsplus[i] = stack_pointer[i];
@@ -3041,12 +3016,8 @@ dummy_func(
new_frame->localsplus[i] = NULL;
}
STACK_SHRINK(2-is_meth);
- _PyFrame_SetStackPointer(frame, stack_pointer);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
- frame->prev_instr = next_instr - 1;
- new_frame->previous = frame;
- frame = cframe.current_frame = new_frame;
- goto start_frame;
+ DISPATCH_INLINED(new_frame);
}
// stack effect: (__0, __array[oparg] -- )
@@ -3067,7 +3038,6 @@ dummy_func(
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
STAT_INC(CALL, hit);
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
- CALL_STAT_INC(inlined_py_calls);
STACK_SHRINK(argcount);
for (int i = 0; i < argcount; i++) {
new_frame->localsplus[i] = stack_pointer[i];
@@ -3081,12 +3051,8 @@ dummy_func(
new_frame->localsplus[i] = NULL;
}
STACK_SHRINK(2-is_meth);
- _PyFrame_SetStackPointer(frame, stack_pointer);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
- frame->prev_instr = next_instr - 1;
- new_frame->previous = frame;
- frame = cframe.current_frame = new_frame;
- goto start_frame;
+ DISPATCH_INLINED(new_frame);
}
// stack effect: (__0, __array[oparg] -- )