Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
GH-113710: Add a "globals to constants" pass#114592
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
3941620 Change optimizer API to provide more information
markshannon665cc58 Add new uops for optimizing globals
markshannon9d9bc24 Optimize LOAD_GLOBAL specializations in tier 2
markshannon24b3533 Fix handling of call stack in trace generator
markshannon35a92cc Get globals to const pass working
markshannon8c699a3 Minor tidying
markshannon28dbecd Merge branch 'main' into globals-to-constants
markshannon99e38ca Merge builtin watchers and limit re-optimizations
markshannone0eaea9 Add braces
markshannond3a2590 Use a few bits in the dict version tag to track deoptimizations
markshannonb3f2418 Address review comments
markshannon0798207 Merge branch 'main' into globals-to-constants
markshannone65dcf2 Tolerate default optimizer being called
markshannonf763e37 Fix compiler warning
markshannon5bdac7a Reduce modification limits a bit.
markshannon3dc8907 Merge branch 'main' into globals-to-constants
markshannonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Get globals to const pass working
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit35a92cccd3aaabf0e86734bbcdc6e0c3ff7eb8c3
There are no files selected for viewing
3 changes: 2 additions & 1 deletionInclude/internal/pycore_optimizer.h
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
28 changes: 14 additions & 14 deletionsLib/test/test_capi/test_watchers.py
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
4 changes: 2 additions & 2 deletionsModules/_testcapi/watchers.c
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -43,7 +43,6 @@ global_to_const(_PyUOpInstruction *inst, PyObject *obj) | ||
| PyDictObject *dict = (PyDictObject *)obj; | ||
| assert(dict->ma_keys->dk_kind == DICT_KEYS_UNICODE); | ||
| PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(dict->ma_keys); | ||
| assert(inst->operand <= UINT16_MAX); | ||
| PyObject *res = entries[inst->operand].me_value; | ||
| if (res == NULL) { | ||
| @@ -59,19 +58,19 @@ global_to_const(_PyUOpInstruction *inst, PyObject *obj) | ||
| } | ||
| static int | ||
| incorrect_keys(_PyUOpInstruction *inst, PyObject *obj) | ||
| { | ||
| if (!PyDict_CheckExact(obj)) { | ||
| return 1; | ||
| } | ||
| PyDictObject *dict = (PyDictObject *)obj; | ||
| if (dict->ma_keys->dk_version != inst->operand) { | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
| staticint | ||
markshannon marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer, | ||
| int buffer_size, _PyBloomFilter *dependencies) | ||
| { | ||
| @@ -104,12 +103,12 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer, | ||
| int opcode = inst->opcode; | ||
| switch(opcode) { | ||
| case _GUARD_BUILTINS_VERSION: | ||
| if (incorrect_keys(inst, builtins)) { | ||
| return 0; | ||
| } | ||
| if ((builtins_watched & 1) == 0) { | ||
| PyDict_Watch(0, builtins); | ||
markshannon marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| builtins_watched|= 1; | ||
| } | ||
| if (builtins_checked & 1) { | ||
| buffer[pc].opcode = NOP; | ||
| @@ -121,8 +120,8 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer, | ||
| } | ||
| break; | ||
| case _GUARD_GLOBALS_VERSION: | ||
| if (incorrect_keys(inst, globals)) { | ||
| return 0; | ||
| } | ||
| if ((globals_watched & 1) == 0) { | ||
| PyDict_Watch(1, globals); | ||
| @@ -139,25 +138,26 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer, | ||
| } | ||
| break; | ||
| case _LOAD_GLOBAL_BUILTINS: | ||
| assert(globals_checked & builtins_checked & globals_watched & builtins_watched & 1); | ||
| global_to_const(inst, builtins); | ||
| break; | ||
| case _LOAD_GLOBAL_MODULE: | ||
| assert(globals_checked & globals_watched & 1); | ||
| global_to_const(inst, globals); | ||
| break; | ||
| case _JUMP_TO_TOP: | ||
| case _EXIT_TRACE: | ||
| return 1; | ||
| case _PUSH_FRAME: | ||
| { | ||
| globals_checked <<= 1; | ||
| globals_watched <<= 1; | ||
| builtins_checked <<= 1; | ||
| builtins_watched <<= 1; | ||
| PyFunctionObject *func = (PyFunctionObject *)buffer[pc].operand; | ||
| if (func == NULL) { | ||
| return 1; | ||
| } | ||
| assert(PyFunction_Check(func)); | ||
| globals = func->func_globals; | ||
| builtins = func->func_builtins; | ||
| @@ -175,8 +175,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer, | ||
| break; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
| static void | ||
| @@ -266,11 +265,15 @@ _Py_uop_analyze_and_optimize( | ||
| _PyInterpreterFrame *frame, | ||
| _PyUOpInstruction *buffer, | ||
| int buffer_size, | ||
| int curr_stacklen, | ||
| _PyBloomFilter *dependencies | ||
| ) | ||
| { | ||
| int err = remove_globals(frame, buffer, buffer_size, dependencies); | ||
| if (err <= 0) { | ||
| return err; | ||
| } | ||
| peephole_opt(frame, buffer, buffer_size); | ||
| remove_unneeded_uops(buffer, buffer_size); | ||
| return1; | ||
| } | ||
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.