Skip to content

Commit 2dfa47c

Browse files
committed
Add stats for GET_ITER
1 parent 844596c commit 2dfa47c

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

Include/internal/pycore_code.h

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int op
315315
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
316316
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
317317
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
318+
extern void _Py_GatherStats_GetIter(_PyStackRef iterable);
318319

319320
// Utility functions for reading/writing 32/64-bit values in the inline caches.
320321
// Great care should be taken to ensure that these functions remain correct and

Python/bytecodes.c

+3
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,9 @@ dummy_func(
30263026
}
30273027

30283028
inst(GET_ITER, (iterable -- iter)) {
3029+
#ifdef Py_STATS
3030+
_Py_GatherStats_GetIter(iterable);
3031+
#endif
30293032
/* before: [obj]; after [getiter(obj)] */
30303033
PyObject *iter_o = PyObject_GetIter(PyStackRef_AsPyObjectBorrow(iterable));
30313034
PyStackRef_CLOSE(iterable);

Python/executor_cases.c.h

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

+12
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ print_spec_stats(FILE *out, OpcodeStats *stats)
146146
* even though we don't specialize them yet. */
147147
fprintf(out, "opcode[BINARY_SLICE].specializable : 1\n");
148148
fprintf(out, "opcode[STORE_SLICE].specializable : 1\n");
149+
fprintf(out, "opcode[GET_ITER].specializable : 1\n");
149150
for (int i = 0; i < 256; i++) {
150151
if (_PyOpcode_Caches[i]) {
151152
/* Ignore jumps as they cannot be specialized */
@@ -3114,6 +3115,17 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
31143115
return;
31153116
}
31163117

3118+
#ifdef Py_STATS
3119+
void
3120+
_Py_GatherStats_GetIter(_PyStackRef iterable)
3121+
{
3122+
PyObject *obj = PyStackRef_AsPyObjectBorrow(iterable);
3123+
int kind = _PySpecialization_ClassifyIterator(obj);
3124+
SPECIALIZATION_FAIL(GET_ITER, kind);
3125+
}
3126+
#endif
3127+
3128+
31173129
/* Code init cleanup.
31183130
* CALL_ALLOC_AND_ENTER_INIT will set up
31193131
* the frame to execute the EXIT_INIT_CHECK

0 commit comments

Comments
 (0)