Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-104584: Optimizer API#105100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
GH-104584: Optimizer API #105100
Changes from all commits
099d919c991ccbc342f26e2d74f36dcd1d54b145a8df9106296715b38801b575b89fb54b70ee71e9822b037a2bc736f7f0977800e2eeebba30d79a6faff8a5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #ifndef Py_LIMITED_API | ||
| #ifndef Py_OPTIMIZER_H | ||
| #define Py_OPTIMIZER_H | ||
| #ifdef __cplusplus | ||
| extern "C"{ | ||
| #endif | ||
| typedef struct{ | ||
| uint8_t opcode; | ||
| uint8_t oparg; | ||
| } _PyVMData; | ||
| typedef struct _PyExecutorObject{ | ||
| PyObject_HEAD | ||
| /* 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); | ||
| _PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */ | ||
| /* Data needed by the executor goes here, but is opaque to the VM */ | ||
| } _PyExecutorObject; | ||
| typedef struct _PyOptimizerObject _PyOptimizerObject; | ||
| typedef _PyExecutorObject *(*optimize_func)(_PyOptimizerObject* self, PyCodeObject *code, _Py_CODEUNIT *instr); | ||
| typedef struct _PyOptimizerObject{ | ||
| PyObject_HEAD | ||
| optimize_func optimize; | ||
| uint16_t resume_threshold; | ||
| uint16_t backedge_threshold; | ||
| /* Data needed by the optimizer goes here, but is opaque to the VM */ | ||
| } _PyOptimizerObject; | ||
| PyAPI_FUNC(int) PyUnstable_Replace_Executor(PyCodeObject *code, _Py_CODEUNIT *instr, _PyExecutorObject *executor); | ||
| PyAPI_FUNC(void) PyUnstable_SetOptimizer(_PyOptimizerObject* optimizer); | ||
| PyAPI_FUNC(_PyOptimizerObject *) PyUnstable_GetOptimizer(void); | ||
| struct _PyInterpreterFrame * | ||
| _PyOptimizer_BackEdge(struct _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest, PyObject **stack_pointer); | ||
| extern _PyOptimizerObject _PyOptimizer_Default; | ||
| /* For testing */ | ||
| PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewCounter(void); | ||
| #define OPTIMIZER_BITS_IN_COUNTER 4 | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif /* !Py_OPTIMIZER_H */ | ||
| #endif /* Py_LIMITED_API */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -160,6 +160,9 @@ struct _is{ | ||
| struct types_state types; | ||
| struct callable_cache callable_cache; | ||
| PyCodeObject *interpreter_trampoline; | ||
| _PyOptimizerObject *optimizer; | ||
| uint16_t optimizer_resume_threshold; | ||
| uint16_t optimizer_backedge_threshold; | ||
markshannon marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| _Py_Monitors monitors; | ||
| bool f_opcode_trace_set; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -232,6 +232,9 @@ def pseudo_op(name, op, real_ops): | ||
| def_op('LOAD_FROM_DICT_OR_DEREF', 176) | ||
| hasfree.append(176) | ||
| # Optimizer hook | ||
| def_op('ENTER_EXECUTOR', 230) | ||
markshannon marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| # Instrumented instructions | ||
| MIN_INSTRUMENTED_OPCODE = 237 | ||
| @@ -486,6 +489,9 @@ def pseudo_op(name, op, real_ops): | ||
| "SEND":{ | ||
| "counter": 1, | ||
| }, | ||
| "JUMP_BACKWARD":{ | ||
| "counter": 1, | ||
| }, | ||
| } | ||
| _inline_cache_entries = [ | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.