-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
Merged
Merged
GH-104584: Optimizer API #105100
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
099d919
Optimizer API. Work in progress.
markshannon c991ccb
Add plugin optimizer API.
markshannon c342f26
Executors are responsible for checking the eval breaker.
markshannon e2d74f3
Rename optimize.c to optimizer.c
markshannon 6dcd1d5
Let the optimizer choose the thresholds
markshannon 4b145a8
Tidy up
markshannon df91062
Make VM responsible for linking in executors. Add test.
markshannon 96715b3
Remove dead code
markshannon 8801b57
Completely turn off optimization when clearing interpreter.
markshannon 5b89fb5
Remove unused function declaration.
markshannon 4b70ee7
Add news
markshannon 1e9822b
Address code review.
markshannon 037a2bc
More precise type for C Api function.
markshannon 736f7f0
Merge branch 'main' into optimizer-api
markshannon 977800e
Add static symbols to list.
markshannon 2eeebba
Address review comments.
markshannon 30d79a6
Merge branch 'main' into optimizer-api
markshannon faff8a5
Address review comments.
markshannon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.