GH-102181: Improve specialization stats for SEND (GH-102182)

This commit is contained in:
penguin_wwy 2023-05-11 06:40:59 +08:00 committed by GitHub
parent 7b8d7f56b6
commit 373bca0cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 44 deletions

View File

@ -77,6 +77,8 @@ PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
#define PyAsyncGen_CheckExact(op) Py_IS_TYPE((op), &PyAsyncGen_Type)
#define PyAsyncGenASend_CheckExact(op) Py_IS_TYPE((op), &_PyAsyncGenASend_Type)
#undef _PyGenObject_HEAD

View File

@ -1406,9 +1406,6 @@ typedef struct _PyAsyncGenWrappedValue {
#define _PyAsyncGenWrappedValue_CheckExact(o) \
Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type)
#define PyAsyncGenASend_CheckExact(o) \
Py_IS_TYPE(o, &_PyAsyncGenASend_Type)
static int
async_gen_traverse(PyAsyncGenObject *gen, visitproc visit, void *arg)

View File

@ -436,27 +436,28 @@ _PyCode_Quicken(PyCodeObject *code)
#define SPEC_FAIL_COMPARE_OP_FLOAT_LONG 21
#define SPEC_FAIL_COMPARE_OP_LONG_FLOAT 22
/* FOR_ITER */
#define SPEC_FAIL_FOR_ITER_GENERATOR 10
#define SPEC_FAIL_FOR_ITER_COROUTINE 11
#define SPEC_FAIL_FOR_ITER_ASYNC_GENERATOR 12
#define SPEC_FAIL_FOR_ITER_LIST 13
#define SPEC_FAIL_FOR_ITER_TUPLE 14
#define SPEC_FAIL_FOR_ITER_SET 15
#define SPEC_FAIL_FOR_ITER_STRING 16
#define SPEC_FAIL_FOR_ITER_BYTES 17
#define SPEC_FAIL_FOR_ITER_RANGE 18
#define SPEC_FAIL_FOR_ITER_ITERTOOLS 19
#define SPEC_FAIL_FOR_ITER_DICT_KEYS 20
#define SPEC_FAIL_FOR_ITER_DICT_ITEMS 21
#define SPEC_FAIL_FOR_ITER_DICT_VALUES 22
#define SPEC_FAIL_FOR_ITER_ENUMERATE 23
#define SPEC_FAIL_FOR_ITER_MAP 24
#define SPEC_FAIL_FOR_ITER_ZIP 25
#define SPEC_FAIL_FOR_ITER_SEQ_ITER 26
#define SPEC_FAIL_FOR_ITER_REVERSED_LIST 27
#define SPEC_FAIL_FOR_ITER_CALLABLE 28
#define SPEC_FAIL_FOR_ITER_ASCII_STRING 29
/* FOR_ITER and SEND */
#define SPEC_FAIL_ITER_GENERATOR 10
#define SPEC_FAIL_ITER_COROUTINE 11
#define SPEC_FAIL_ITER_ASYNC_GENERATOR 12
#define SPEC_FAIL_ITER_LIST 13
#define SPEC_FAIL_ITER_TUPLE 14
#define SPEC_FAIL_ITER_SET 15
#define SPEC_FAIL_ITER_STRING 16
#define SPEC_FAIL_ITER_BYTES 17
#define SPEC_FAIL_ITER_RANGE 18
#define SPEC_FAIL_ITER_ITERTOOLS 19
#define SPEC_FAIL_ITER_DICT_KEYS 20
#define SPEC_FAIL_ITER_DICT_ITEMS 21
#define SPEC_FAIL_ITER_DICT_VALUES 22
#define SPEC_FAIL_ITER_ENUMERATE 23
#define SPEC_FAIL_ITER_MAP 24
#define SPEC_FAIL_ITER_ZIP 25
#define SPEC_FAIL_ITER_SEQ_ITER 26
#define SPEC_FAIL_ITER_REVERSED_LIST 27
#define SPEC_FAIL_ITER_CALLABLE 28
#define SPEC_FAIL_ITER_ASCII_STRING 29
#define SPEC_FAIL_ITER_ASYNC_GENERATOR_SEND 30
// UNPACK_SEQUENCE
@ -2122,66 +2123,69 @@ int
_PySpecialization_ClassifyIterator(PyObject *iter)
{
if (PyGen_CheckExact(iter)) {
return SPEC_FAIL_FOR_ITER_GENERATOR;
return SPEC_FAIL_ITER_GENERATOR;
}
if (PyCoro_CheckExact(iter)) {
return SPEC_FAIL_FOR_ITER_COROUTINE;
return SPEC_FAIL_ITER_COROUTINE;
}
if (PyAsyncGen_CheckExact(iter)) {
return SPEC_FAIL_FOR_ITER_ASYNC_GENERATOR;
return SPEC_FAIL_ITER_ASYNC_GENERATOR;
}
if (PyAsyncGenASend_CheckExact(iter)) {
return SPEC_FAIL_ITER_ASYNC_GENERATOR_SEND;
}
PyTypeObject *t = Py_TYPE(iter);
if (t == &PyListIter_Type) {
return SPEC_FAIL_FOR_ITER_LIST;
return SPEC_FAIL_ITER_LIST;
}
if (t == &PyTupleIter_Type) {
return SPEC_FAIL_FOR_ITER_TUPLE;
return SPEC_FAIL_ITER_TUPLE;
}
if (t == &PyDictIterKey_Type) {
return SPEC_FAIL_FOR_ITER_DICT_KEYS;
return SPEC_FAIL_ITER_DICT_KEYS;
}
if (t == &PyDictIterValue_Type) {
return SPEC_FAIL_FOR_ITER_DICT_VALUES;
return SPEC_FAIL_ITER_DICT_VALUES;
}
if (t == &PyDictIterItem_Type) {
return SPEC_FAIL_FOR_ITER_DICT_ITEMS;
return SPEC_FAIL_ITER_DICT_ITEMS;
}
if (t == &PySetIter_Type) {
return SPEC_FAIL_FOR_ITER_SET;
return SPEC_FAIL_ITER_SET;
}
if (t == &PyUnicodeIter_Type) {
return SPEC_FAIL_FOR_ITER_STRING;
return SPEC_FAIL_ITER_STRING;
}
if (t == &PyBytesIter_Type) {
return SPEC_FAIL_FOR_ITER_BYTES;
return SPEC_FAIL_ITER_BYTES;
}
if (t == &PyRangeIter_Type) {
return SPEC_FAIL_FOR_ITER_RANGE;
return SPEC_FAIL_ITER_RANGE;
}
if (t == &PyEnum_Type) {
return SPEC_FAIL_FOR_ITER_ENUMERATE;
return SPEC_FAIL_ITER_ENUMERATE;
}
if (t == &PyMap_Type) {
return SPEC_FAIL_FOR_ITER_MAP;
return SPEC_FAIL_ITER_MAP;
}
if (t == &PyZip_Type) {
return SPEC_FAIL_FOR_ITER_ZIP;
return SPEC_FAIL_ITER_ZIP;
}
if (t == &PySeqIter_Type) {
return SPEC_FAIL_FOR_ITER_SEQ_ITER;
return SPEC_FAIL_ITER_SEQ_ITER;
}
if (t == &PyListRevIter_Type) {
return SPEC_FAIL_FOR_ITER_REVERSED_LIST;
return SPEC_FAIL_ITER_REVERSED_LIST;
}
if (t == &_PyUnicodeASCIIIter_Type) {
return SPEC_FAIL_FOR_ITER_ASCII_STRING;
return SPEC_FAIL_ITER_ASCII_STRING;
}
const char *name = t->tp_name;
if (strncmp(name, "itertools", 9) == 0) {
return SPEC_FAIL_FOR_ITER_ITERTOOLS;
return SPEC_FAIL_ITER_ITERTOOLS;
}
if (strncmp(name, "callable_iterator", 17) == 0) {
return SPEC_FAIL_FOR_ITER_CALLABLE;
return SPEC_FAIL_ITER_CALLABLE;
}
return SPEC_FAIL_OTHER;
}

View File

@ -228,6 +228,8 @@ def kind_to_text(kind, defines, opname):
return pretty(defines[kind][0])
if opname.endswith("ATTR"):
opname = "ATTR"
if opname in ("FOR_ITER", "SEND"):
opname = "ITER"
if opname.endswith("SUBSCR"):
opname = "SUBSCR"
for name in defines[kind]: