|
| 1 | + |
| 2 | +#ifndef Py_LIMITED_API |
| 3 | +#ifndef Py_OPTIMIZER_H |
| 4 | +#define Py_OPTIMIZER_H |
| 5 | +#ifdef __cplusplus |
| 6 | +extern "C" { |
| 7 | +#endif |
| 8 | + |
| 9 | +typedef struct { |
| 10 | + uint8_t opcode; |
| 11 | + uint8_t oparg; |
| 12 | +} _PyVMData; |
| 13 | + |
| 14 | +typedef struct _PyExecutorObject { |
| 15 | + PyObject_HEAD |
| 16 | + /* WARNING: execute consumes a reference to self. This is necessary to allow executors to tail call into each other. */ |
| 17 | + struct _PyInterpreterFrame *(*execute)(struct _PyExecutorObject *self, struct _PyInterpreterFrame *frame, PyObject **stack_pointer); |
| 18 | + _PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */ |
| 19 | + /* Data needed by the executor goes here, but is opaque to the VM */ |
| 20 | +} _PyExecutorObject; |
| 21 | + |
| 22 | +typedef struct _PyOptimizerObject _PyOptimizerObject; |
| 23 | + |
| 24 | +typedef _PyExecutorObject *(*optimize_func)(_PyOptimizerObject* self, PyCodeObject *code, _Py_CODEUNIT *instr); |
| 25 | + |
| 26 | +typedef struct _PyOptimizerObject { |
| 27 | + PyObject_HEAD |
| 28 | + optimize_func optimize; |
| 29 | + uint16_t resume_threshold; |
| 30 | + uint16_t backedge_threshold; |
| 31 | + /* Data needed by the optimizer goes here, but is opaque to the VM */ |
| 32 | +} _PyOptimizerObject; |
| 33 | + |
| 34 | +PyAPI_FUNC(int) PyUnstable_Replace_Executor(PyCodeObject *code, _Py_CODEUNIT *instr, _PyExecutorObject *executor); |
| 35 | + |
| 36 | +PyAPI_FUNC(void) PyUnstable_SetOptimizer(_PyOptimizerObject* optimizer); |
| 37 | + |
| 38 | +PyAPI_FUNC(_PyOptimizerObject *) PyUnstable_GetOptimizer(void); |
| 39 | + |
| 40 | +struct _PyInterpreterFrame * |
| 41 | +_PyOptimizer_BackEdge(struct _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest, PyObject **stack_pointer); |
| 42 | + |
| 43 | +extern _PyOptimizerObject _PyOptimizer_Default; |
| 44 | + |
| 45 | +/* For testing */ |
| 46 | +PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewCounter(void); |
| 47 | + |
| 48 | +#define OPTIMIZER_BITS_IN_COUNTER 4 |
| 49 | + |
| 50 | +#ifdef __cplusplus |
| 51 | +} |
| 52 | +#endif |
| 53 | +#endif /* !Py_OPTIMIZER_H */ |
| 54 | +#endif /* Py_LIMITED_API */ |
0 commit comments