bpo-44889: Specialize LOAD_METHOD with PEP 659 adaptive interpreter (GH-27722)

Adds four new instructions:

* LOAD_METHOD_ADAPTIVE
* LOAD_METHOD_CACHED
* LOAD_METHOD_MODULE
* LOAD_METHOD_CLASS
This commit is contained in:
Ken Jin 2021-08-17 22:55:55 +08:00 committed by GitHub
parent fcd651d16f
commit 96346cb6d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 351 additions and 46 deletions

View file

@ -30,6 +30,11 @@ typedef struct {
uint32_t builtin_keys_version;
} _PyLoadGlobalCache;
typedef struct {
/* Borrowed ref in LOAD_METHOD */
PyObject *obj;
} _PyObjectCache;
/* Add specialized versions of entries to this union.
*
* Do not break the invariant: sizeof(SpecializedCacheEntry) == 8
@ -45,6 +50,7 @@ typedef union {
_PyAdaptiveEntry adaptive;
_PyAttrCache attr;
_PyLoadGlobalCache load_global;
_PyObjectCache obj;
} SpecializedCacheEntry;
#define INSTRUCTIONS_PER_ENTRY (sizeof(SpecializedCacheEntry)/sizeof(_Py_CODEUNIT))
@ -299,6 +305,7 @@ cache_backoff(_PyAdaptiveEntry *entry) {
int _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
int _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
int _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
#define PRINT_SPECIALIZATION_STATS 0