mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-120619: Optimize through _Py_FRAME_GENERAL
(GH-124518)
* Optimize through _Py_FRAME_GENERAL * refactor
This commit is contained in:
parent
8cc5aa47ee
commit
b84a763dca
3 changed files with 54 additions and 47 deletions
|
@ -385,6 +385,30 @@ get_code(_PyUOpInstruction *op)
|
||||||
return co;
|
return co;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyCodeObject *
|
||||||
|
get_code_with_logging(_PyUOpInstruction *op)
|
||||||
|
{
|
||||||
|
PyCodeObject *co = NULL;
|
||||||
|
uint64_t push_operand = op->operand;
|
||||||
|
if (push_operand & 1) {
|
||||||
|
co = (PyCodeObject *)(push_operand & ~1);
|
||||||
|
DPRINTF(3, "code=%p ", co);
|
||||||
|
assert(PyCode_Check(co));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyFunctionObject *func = (PyFunctionObject *)push_operand;
|
||||||
|
DPRINTF(3, "func=%p ", func);
|
||||||
|
if (func == NULL) {
|
||||||
|
DPRINTF(3, "\n");
|
||||||
|
DPRINTF(1, "Missing function\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
co = (PyCodeObject *)func->func_code;
|
||||||
|
DPRINTF(3, "code=%p ", co);
|
||||||
|
}
|
||||||
|
return co;
|
||||||
|
}
|
||||||
|
|
||||||
/* 1 for success, 0 for not ready, cannot error at the moment. */
|
/* 1 for success, 0 for not ready, cannot error at the moment. */
|
||||||
static int
|
static int
|
||||||
optimize_uops(
|
optimize_uops(
|
||||||
|
|
|
@ -575,25 +575,13 @@ dummy_func(void) {
|
||||||
|
|
||||||
PyCodeObject *co = NULL;
|
PyCodeObject *co = NULL;
|
||||||
assert((this_instr + 2)->opcode == _PUSH_FRAME);
|
assert((this_instr + 2)->opcode == _PUSH_FRAME);
|
||||||
uint64_t push_operand = (this_instr + 2)->operand;
|
co = get_code_with_logging((this_instr + 2));
|
||||||
if (push_operand & 1) {
|
if (co == NULL) {
|
||||||
co = (PyCodeObject *)(push_operand & ~1);
|
ctx->done = true;
|
||||||
DPRINTF(3, "code=%p ", co);
|
break;
|
||||||
assert(PyCode_Check(co));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
PyFunctionObject *func = (PyFunctionObject *)push_operand;
|
|
||||||
DPRINTF(3, "func=%p ", func);
|
|
||||||
if (func == NULL) {
|
|
||||||
DPRINTF(3, "\n");
|
|
||||||
DPRINTF(1, "Missing function\n");
|
|
||||||
ctx->done = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
co = (PyCodeObject *)func->func_code;
|
|
||||||
DPRINTF(3, "code=%p ", co);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
assert(self_or_null != NULL);
|
assert(self_or_null != NULL);
|
||||||
assert(args != NULL);
|
assert(args != NULL);
|
||||||
if (sym_is_not_null(self_or_null)) {
|
if (sym_is_not_null(self_or_null)) {
|
||||||
|
@ -619,12 +607,17 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
|
op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
|
||||||
/* The _Py_UOpsAbstractFrame design assumes that we can copy arguments across directly */
|
(void)(self_or_null);
|
||||||
(void)callable;
|
(void)(callable);
|
||||||
(void)self_or_null;
|
PyCodeObject *co = NULL;
|
||||||
(void)args;
|
assert((this_instr + 2)->opcode == _PUSH_FRAME);
|
||||||
new_frame = NULL;
|
co = get_code_with_logging((this_instr + 2));
|
||||||
ctx->done = true;
|
if (co == NULL) {
|
||||||
|
ctx->done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_frame = frame_new(ctx, co, 0, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_PY_FRAME_KW, (callable, self_or_null, args[oparg], kwnames -- new_frame: _Py_UOpsAbstractFrame *)) {
|
op(_PY_FRAME_KW, (callable, self_or_null, args[oparg], kwnames -- new_frame: _Py_UOpsAbstractFrame *)) {
|
||||||
|
|
38
Python/optimizer_cases.c.h
generated
38
Python/optimizer_cases.c.h
generated
|
@ -1663,15 +1663,18 @@
|
||||||
_Py_UopsSymbol *self_or_null;
|
_Py_UopsSymbol *self_or_null;
|
||||||
_Py_UopsSymbol *callable;
|
_Py_UopsSymbol *callable;
|
||||||
_Py_UOpsAbstractFrame *new_frame;
|
_Py_UOpsAbstractFrame *new_frame;
|
||||||
args = &stack_pointer[-oparg];
|
|
||||||
self_or_null = stack_pointer[-1 - oparg];
|
self_or_null = stack_pointer[-1 - oparg];
|
||||||
callable = stack_pointer[-2 - oparg];
|
callable = stack_pointer[-2 - oparg];
|
||||||
/* The _Py_UOpsAbstractFrame design assumes that we can copy arguments across directly */
|
(void)(self_or_null);
|
||||||
(void)callable;
|
(void)(callable);
|
||||||
(void)self_or_null;
|
PyCodeObject *co = NULL;
|
||||||
(void)args;
|
assert((this_instr + 2)->opcode == _PUSH_FRAME);
|
||||||
new_frame = NULL;
|
co = get_code_with_logging((this_instr + 2));
|
||||||
ctx->done = true;
|
if (co == NULL) {
|
||||||
|
ctx->done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
new_frame = frame_new(ctx, co, 0, NULL, 0);
|
||||||
stack_pointer[-2 - oparg] = (_Py_UopsSymbol *)new_frame;
|
stack_pointer[-2 - oparg] = (_Py_UopsSymbol *)new_frame;
|
||||||
stack_pointer += -1 - oparg;
|
stack_pointer += -1 - oparg;
|
||||||
assert(WITHIN_STACK_BOUNDS());
|
assert(WITHIN_STACK_BOUNDS());
|
||||||
|
@ -1771,23 +1774,10 @@
|
||||||
(void)callable;
|
(void)callable;
|
||||||
PyCodeObject *co = NULL;
|
PyCodeObject *co = NULL;
|
||||||
assert((this_instr + 2)->opcode == _PUSH_FRAME);
|
assert((this_instr + 2)->opcode == _PUSH_FRAME);
|
||||||
uint64_t push_operand = (this_instr + 2)->operand;
|
co = get_code_with_logging((this_instr + 2));
|
||||||
if (push_operand & 1) {
|
if (co == NULL) {
|
||||||
co = (PyCodeObject *)(push_operand & ~1);
|
ctx->done = true;
|
||||||
DPRINTF(3, "code=%p ", co);
|
break;
|
||||||
assert(PyCode_Check(co));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
PyFunctionObject *func = (PyFunctionObject *)push_operand;
|
|
||||||
DPRINTF(3, "func=%p ", func);
|
|
||||||
if (func == NULL) {
|
|
||||||
DPRINTF(3, "\n");
|
|
||||||
DPRINTF(1, "Missing function\n");
|
|
||||||
ctx->done = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
co = (PyCodeObject *)func->func_code;
|
|
||||||
DPRINTF(3, "code=%p ", co);
|
|
||||||
}
|
}
|
||||||
assert(self_or_null != NULL);
|
assert(self_or_null != NULL);
|
||||||
assert(args != NULL);
|
assert(args != NULL);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue