GH-113710: Add a "globals to constants" pass (GH-114592)

Converts specializations of `LOAD_GLOBAL` into constants during tier 2 optimization.
This commit is contained in:
Mark Shannon 2024-02-02 12:14:34 +00:00 committed by GitHub
parent 2091fb2a85
commit 0e71a295e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 375 additions and 55 deletions

View file

@ -3393,6 +3393,7 @@
case _LOAD_CONST_INLINE: {
PyObject *value;
PyObject *ptr = (PyObject *)CURRENT_OPERAND();
TIER_TWO_ONLY
value = Py_NewRef(ptr);
stack_pointer[0] = value;
stack_pointer += 1;
@ -3402,12 +3403,53 @@
case _LOAD_CONST_INLINE_BORROW: {
PyObject *value;
PyObject *ptr = (PyObject *)CURRENT_OPERAND();
TIER_TWO_ONLY
value = ptr;
stack_pointer[0] = value;
stack_pointer += 1;
break;
}
case _LOAD_CONST_INLINE_WITH_NULL: {
PyObject *value;
PyObject *null;
PyObject *ptr = (PyObject *)CURRENT_OPERAND();
TIER_TWO_ONLY
value = Py_NewRef(ptr);
null = NULL;
stack_pointer[0] = value;
stack_pointer[1] = null;
stack_pointer += 2;
break;
}
case _LOAD_CONST_INLINE_BORROW_WITH_NULL: {
PyObject *value;
PyObject *null;
PyObject *ptr = (PyObject *)CURRENT_OPERAND();
TIER_TWO_ONLY
value = ptr;
null = NULL;
stack_pointer[0] = value;
stack_pointer[1] = null;
stack_pointer += 2;
break;
}
case _CHECK_GLOBALS: {
PyObject *dict = (PyObject *)CURRENT_OPERAND();
TIER_TWO_ONLY
if (GLOBALS() != dict) goto deoptimize;
break;
}
case _CHECK_BUILTINS: {
PyObject *dict = (PyObject *)CURRENT_OPERAND();
TIER_TWO_ONLY
if (BUILTINS() != dict) goto deoptimize;
break;
}
case _INTERNAL_INCREMENT_OPT_COUNTER: {
PyObject *opt;
opt = stack_pointer[-1];