mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
gh-106608: make uop trace variable length (#107531)
Executors are now more like tuples.
This commit is contained in:
parent
05a824f294
commit
4e6fac7fcc
4 changed files with 7 additions and 15 deletions
|
@ -12,7 +12,7 @@ typedef struct {
|
||||||
} _PyVMData;
|
} _PyVMData;
|
||||||
|
|
||||||
typedef struct _PyExecutorObject {
|
typedef struct _PyExecutorObject {
|
||||||
PyObject_HEAD
|
PyObject_VAR_HEAD
|
||||||
/* WARNING: execute consumes a reference to self. This is necessary to allow executors to tail call into each other. */
|
/* WARNING: execute consumes a reference to self. This is necessary to allow executors to tail call into each other. */
|
||||||
struct _PyInterpreterFrame *(*execute)(struct _PyExecutorObject *self, struct _PyInterpreterFrame *frame, PyObject **stack_pointer);
|
struct _PyInterpreterFrame *(*execute)(struct _PyExecutorObject *self, struct _PyInterpreterFrame *frame, PyObject **stack_pointer);
|
||||||
_PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */
|
_PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */
|
||||||
|
|
|
@ -18,7 +18,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
_PyExecutorObject base;
|
_PyExecutorObject base;
|
||||||
_PyUOpInstruction trace[_Py_UOP_MAX_TRACE_LENGTH]; // TODO: variable length
|
_PyUOpInstruction trace[1];
|
||||||
} _PyUOpExecutorObject;
|
} _PyUOpExecutorObject;
|
||||||
|
|
||||||
_PyInterpreterFrame *_PyUopExecute(
|
_PyInterpreterFrame *_PyUopExecute(
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make ``_PyUOpExecutorObject`` variable length.
|
|
@ -320,13 +320,7 @@ uop_name(int index) {
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
uop_len(_PyUOpExecutorObject *self)
|
uop_len(_PyUOpExecutorObject *self)
|
||||||
{
|
{
|
||||||
int count = 0;
|
return Py_SIZE(self);
|
||||||
for (; count < _Py_UOP_MAX_TRACE_LENGTH; count++) {
|
|
||||||
if (self->trace[count].opcode == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -368,8 +362,8 @@ PySequenceMethods uop_as_sequence = {
|
||||||
static PyTypeObject UOpExecutor_Type = {
|
static PyTypeObject UOpExecutor_Type = {
|
||||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||||
.tp_name = "uop_executor",
|
.tp_name = "uop_executor",
|
||||||
.tp_basicsize = sizeof(_PyUOpExecutorObject),
|
.tp_basicsize = sizeof(_PyUOpExecutorObject) - sizeof(_PyUOpInstruction),
|
||||||
.tp_itemsize = 0,
|
.tp_itemsize = sizeof(_PyUOpInstruction),
|
||||||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||||
.tp_dealloc = (destructor)uop_dealloc,
|
.tp_dealloc = (destructor)uop_dealloc,
|
||||||
.tp_as_sequence = &uop_as_sequence,
|
.tp_as_sequence = &uop_as_sequence,
|
||||||
|
@ -699,15 +693,12 @@ uop_optimize(
|
||||||
return trace_length;
|
return trace_length;
|
||||||
}
|
}
|
||||||
OBJECT_STAT_INC(optimization_traces_created);
|
OBJECT_STAT_INC(optimization_traces_created);
|
||||||
_PyUOpExecutorObject *executor = PyObject_New(_PyUOpExecutorObject, &UOpExecutor_Type);
|
_PyUOpExecutorObject *executor = PyObject_NewVar(_PyUOpExecutorObject, &UOpExecutor_Type, trace_length);
|
||||||
if (executor == NULL) {
|
if (executor == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
executor->base.execute = _PyUopExecute;
|
executor->base.execute = _PyUopExecute;
|
||||||
memcpy(executor->trace, trace, trace_length * sizeof(_PyUOpInstruction));
|
memcpy(executor->trace, trace, trace_length * sizeof(_PyUOpInstruction));
|
||||||
if (trace_length < _Py_UOP_MAX_TRACE_LENGTH) {
|
|
||||||
executor->trace[trace_length].opcode = 0; // Sentinel
|
|
||||||
}
|
|
||||||
*exec_ptr = (_PyExecutorObject *)executor;
|
*exec_ptr = (_PyExecutorObject *)executor;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue