8000 GH-104909: Break LOAD_GLOBAL specializations in micro-ops. by markshannon · Pull Request #106677 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-104909: Break LOAD_GLOBAL specializations in micro-ops. #106677

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 8 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Break LOAD_GLOBAL specializations in micro-ops. WIP.
  • Loading branch information
markshannon committed Jun 1, 2023
commit c57e981381ebbcd732d5814ec7f4c0d6a78cc3ca
2 changes: 1 addition & 1 deletion Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ extern "C" {

typedef struct {
uint16_t counter;
uint16_t index;
uint16_t module_keys_version;
uint16_t builtin_keys_version;
uint16_t index;
} _PyLoadGlobalCache;

#define INLINE_CACHE_ENTRIES_LOAD_GLOBAL CACHE_ENTRIES(_PyLoadGlobalCache)
Expand Down
31 changes: 21 additions & 10 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,11 +1314,25 @@ dummy_func(
null = NULL;
}

inst(LOAD_GLOBAL_MODULE, (unused/1, index/1, version/1, unused/1 -- null if (oparg & 1), res)) {
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
op(_SKIP_CACHE, (unused/1 -- )) {
}

op(_GUARD_GLOBALS_VERSION, (version/1 --)) {
PyDictObject *dict = (PyDictObject *)GLOBALS();
DEOPT_IF(!PyDict_CheckExact(dict), LOAD_GLOBAL);
DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
assert(DK_IS_UNICODE(dict->ma_keys));
}

op(_GUARD_BUILTINS_VERSION, (version/1 --)) {
PyDictObject *dict = (PyDictObject *)BUILTINS();
DEOPT_IF(!PyDict_CheckExact(dict), LOAD_GLOBAL);
DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
assert(DK_IS_UNICODE(dict->ma_keys));
}

op(_LOAD_GLOBAL_MODULE, (index/1 -- null if (oparg & 1), res)) {
PyDictObject *dict = (PyDictObject *)GLOBALS();
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(dict->ma_keys);
res = entries[index].me_value;
DEOPT_IF(res == NULL, LOAD_GLOBAL);
Expand All @@ -1327,15 +1341,8 @@ dummy_func(
null = NULL;
}

inst(LOAD_GLOBAL_BUILTIN, (unused/1, index/1, mod_version/1, bltn_version/1 -- null if (oparg & 1), res)) {
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL);
PyDictObject *mdict = (PyDictObject *)GLOBALS();
op(_LOAD_GLOBAL_BUILTINS, (index/1 -- null if (oparg & 1), res)) {
PyDictObject *bdict = (PyDictObject *)BUILTINS();
assert(opcode == LOAD_GLOBAL_BUILTIN);
DEOPT_IF(mdict->ma_keys->dk_version != mod_version, LOAD_GLOBAL);
DEOPT_IF(bdict->ma_keys->dk_version != bltn_version, LOAD_GLOBAL);
assert(DK_IS_UNICODE(bdict->ma_keys));
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(bdict->ma_keys);
res = entries[index].me_value;
DEOPT_IF(res == NULL, LOAD_GLOBAL);
Expand All @@ -1344,6 +1351,10 @@ dummy_func(
null = NULL;
}

macro(LOAD_GLOBAL_MODULE) = _SKIP_CACHE + _GUARD_GLOBALS_VERSION + _SKIP_CACHE + _LOAD_GLOBAL_MODULE;

macro(LOAD_GLOBAL_BUILTIN) = _SKIP_CACHE + _GUARD_GLOBALS_VERSION + _GUARD_BUILTINS_VERSION + _LOAD_GLOBAL_BUILTINS;

inst(DELETE_FAST, (--)) {
PyObject *v = GETLOCAL(oparg);
ERROR_IF(v == NULL, unbound_local_error);
Expand Down
0