mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Add a macro for "inlining" new frames (GH-99490)
This commit is contained in:
parent
a0d940d6ac
commit
6f8b0e781c
3 changed files with 28 additions and 86 deletions
|
@ -467,13 +467,8 @@ dummy_func(
|
||||||
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
|
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack effect: (__0 -- )
|
// stack effect: (__0 -- )
|
||||||
|
@ -1938,13 +1933,8 @@ dummy_func(
|
||||||
for (int i = 1; i < code->co_nlocalsplus; i++) {
|
for (int i = 1; i < code->co_nlocalsplus; i++) {
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// error: LOAD_ATTR has irregular stack effect
|
// error: LOAD_ATTR has irregular stack effect
|
||||||
|
@ -1979,13 +1969,8 @@ dummy_func(
|
||||||
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack effect: (__0, __1 -- )
|
// stack effect: (__0, __1 -- )
|
||||||
|
@ -2685,18 +2670,14 @@ dummy_func(
|
||||||
DEOPT_IF(gen->gi_frame_state >= FRAME_EXECUTING, FOR_ITER);
|
DEOPT_IF(gen->gi_frame_state >= FRAME_EXECUTING, FOR_ITER);
|
||||||
STAT_INC(FOR_ITER, hit);
|
STAT_INC(FOR_ITER, hit);
|
||||||
_PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
|
_PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
frame->yield_offset = oparg;
|
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));
|
_PyFrame_StackPush(gen_frame, Py_NewRef(Py_None));
|
||||||
gen->gi_frame_state = FRAME_EXECUTING;
|
gen->gi_frame_state = FRAME_EXECUTING;
|
||||||
gen->gi_exc_state.previous_item = tstate->exc_info;
|
gen->gi_exc_state.previous_item = tstate->exc_info;
|
||||||
tstate->exc_info = &gen->gi_exc_state;
|
tstate->exc_info = &gen->gi_exc_state;
|
||||||
gen_frame->previous = frame;
|
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
|
||||||
frame = cframe.current_frame = gen_frame;
|
assert(_Py_OPCODE(*next_instr) == END_FOR);
|
||||||
goto start_frame;
|
DISPATCH_INLINED(gen_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack effect: ( -- __0)
|
// stack effect: ( -- __0)
|
||||||
|
@ -2978,13 +2959,8 @@ dummy_func(
|
||||||
if (new_frame == NULL) {
|
if (new_frame == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
cframe.current_frame = frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
/* Callable is not a normal Python function */
|
/* Callable is not a normal Python function */
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
|
@ -3032,7 +3008,6 @@ dummy_func(
|
||||||
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
||||||
STAT_INC(CALL, hit);
|
STAT_INC(CALL, hit);
|
||||||
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
STACK_SHRINK(argcount);
|
STACK_SHRINK(argcount);
|
||||||
for (int i = 0; i < argcount; i++) {
|
for (int i = 0; i < argcount; i++) {
|
||||||
new_frame->localsplus[i] = stack_pointer[i];
|
new_frame->localsplus[i] = stack_pointer[i];
|
||||||
|
@ -3041,12 +3016,8 @@ dummy_func(
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
STACK_SHRINK(2-is_meth);
|
STACK_SHRINK(2-is_meth);
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack effect: (__0, __array[oparg] -- )
|
// stack effect: (__0, __array[oparg] -- )
|
||||||
|
@ -3067,7 +3038,6 @@ dummy_func(
|
||||||
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
||||||
STAT_INC(CALL, hit);
|
STAT_INC(CALL, hit);
|
||||||
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
STACK_SHRINK(argcount);
|
STACK_SHRINK(argcount);
|
||||||
for (int i = 0; i < argcount; i++) {
|
for (int i = 0; i < argcount; i++) {
|
||||||
new_frame->localsplus[i] = stack_pointer[i];
|
new_frame->localsplus[i] = stack_pointer[i];
|
||||||
|
@ -3081,12 +3051,8 @@ dummy_func(
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
STACK_SHRINK(2-is_meth);
|
STACK_SHRINK(2-is_meth);
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stack effect: (__0, __array[oparg] -- )
|
// stack effect: (__0, __array[oparg] -- )
|
||||||
|
|
|
@ -712,6 +712,16 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
DISPATCH_GOTO(); \
|
DISPATCH_GOTO(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DISPATCH_INLINED(NEW_FRAME) \
|
||||||
|
do { \
|
||||||
|
_PyFrame_SetStackPointer(frame, stack_pointer); \
|
||||||
|
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; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define CHECK_EVAL_BREAKER() \
|
#define CHECK_EVAL_BREAKER() \
|
||||||
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \
|
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \
|
||||||
if (_Py_atomic_load_relaxed_int32(eval_breaker)) { \
|
if (_Py_atomic_load_relaxed_int32(eval_breaker)) { \
|
||||||
|
|
52
Python/generated_cases.c.h
generated
52
Python/generated_cases.c.h
generated
|
@ -461,13 +461,8 @@
|
||||||
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
|
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(LIST_APPEND) {
|
TARGET(LIST_APPEND) {
|
||||||
|
@ -1942,13 +1937,8 @@
|
||||||
for (int i = 1; i < code->co_nlocalsplus; i++) {
|
for (int i = 1; i < code->co_nlocalsplus; i++) {
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) {
|
TARGET(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) {
|
||||||
|
@ -1982,13 +1972,8 @@
|
||||||
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
for (int i = 2; i < code->co_nlocalsplus; i++) {
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(STORE_ATTR_INSTANCE_VALUE) {
|
TARGET(STORE_ATTR_INSTANCE_VALUE) {
|
||||||
|
@ -2692,18 +2677,14 @@
|
||||||
DEOPT_IF(gen->gi_frame_state >= FRAME_EXECUTING, FOR_ITER);
|
DEOPT_IF(gen->gi_frame_state >= FRAME_EXECUTING, FOR_ITER);
|
||||||
STAT_INC(FOR_ITER, hit);
|
STAT_INC(FOR_ITER, hit);
|
||||||
_PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
|
_PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
frame->yield_offset = oparg;
|
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));
|
_PyFrame_StackPush(gen_frame, Py_NewRef(Py_None));
|
||||||
gen->gi_frame_state = FRAME_EXECUTING;
|
gen->gi_frame_state = FRAME_EXECUTING;
|
||||||
gen->gi_exc_state.previous_item = tstate->exc_info;
|
gen->gi_exc_state.previous_item = tstate->exc_info;
|
||||||
tstate->exc_info = &gen->gi_exc_state;
|
tstate->exc_info = &gen->gi_exc_state;
|
||||||
gen_frame->previous = frame;
|
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
|
||||||
frame = cframe.current_frame = gen_frame;
|
assert(_Py_OPCODE(*next_instr) == END_FOR);
|
||||||
goto start_frame;
|
DISPATCH_INLINED(gen_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(BEFORE_ASYNC_WITH) {
|
TARGET(BEFORE_ASYNC_WITH) {
|
||||||
|
@ -2983,13 +2964,8 @@
|
||||||
if (new_frame == NULL) {
|
if (new_frame == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
cframe.current_frame = frame = new_frame;
|
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
/* Callable is not a normal Python function */
|
/* Callable is not a normal Python function */
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
|
@ -3038,7 +3014,6 @@
|
||||||
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
||||||
STAT_INC(CALL, hit);
|
STAT_INC(CALL, hit);
|
||||||
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
STACK_SHRINK(argcount);
|
STACK_SHRINK(argcount);
|
||||||
for (int i = 0; i < argcount; i++) {
|
for (int i = 0; i < argcount; i++) {
|
||||||
new_frame->localsplus[i] = stack_pointer[i];
|
new_frame->localsplus[i] = stack_pointer[i];
|
||||||
|
@ -3047,12 +3022,8 @@
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
STACK_SHRINK(2-is_meth);
|
STACK_SHRINK(2-is_meth);
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(CALL_PY_WITH_DEFAULTS) {
|
TARGET(CALL_PY_WITH_DEFAULTS) {
|
||||||
|
@ -3072,7 +3043,6 @@
|
||||||
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
|
||||||
STAT_INC(CALL, hit);
|
STAT_INC(CALL, hit);
|
||||||
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
|
||||||
CALL_STAT_INC(inlined_py_calls);
|
|
||||||
STACK_SHRINK(argcount);
|
STACK_SHRINK(argcount);
|
||||||
for (int i = 0; i < argcount; i++) {
|
for (int i = 0; i < argcount; i++) {
|
||||||
new_frame->localsplus[i] = stack_pointer[i];
|
new_frame->localsplus[i] = stack_pointer[i];
|
||||||
|
@ -3086,12 +3056,8 @@
|
||||||
new_frame->localsplus[i] = NULL;
|
new_frame->localsplus[i] = NULL;
|
||||||
}
|
}
|
||||||
STACK_SHRINK(2-is_meth);
|
STACK_SHRINK(2-is_meth);
|
||||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
|
||||||
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
|
||||||
frame->prev_instr = next_instr - 1;
|
DISPATCH_INLINED(new_frame);
|
||||||
new_frame->previous = frame;
|
|
||||||
frame = cframe.current_frame = new_frame;
|
|
||||||
goto start_frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TARGET(CALL_NO_KW_TYPE_1) {
|
TARGET(CALL_NO_KW_TYPE_1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue