Skip to content

Commit e4f2147

Browse files
Make deopts significantly more efficient
1 parent 297f5b9 commit e4f2147

File tree

6 files changed

+472
-470
lines changed

6 files changed

+472
-470
lines changed

Lib/test/test_generated_cases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def test_predictions(self):
460460
INSTRUCTION_STATS(OP3);
461461
static_assert(INLINE_CACHE_ENTRIES_OP1 == 0, "incorrect cache size");
462462
_PyStackRef res;
463-
DEOPT_IF(xxx, OP1);
463+
DEOPT_IF(xxx, OP1, INLINE_CACHE_ENTRIES_OP1);
464464
res = Py_None;
465465
stack_pointer[-1] = res;
466466
DISPATCH();

Python/bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include "ceval_macros.h"
4646

4747
/* Flow control macros */
48-
#define GO_TO_INSTRUCTION(instname) ((void)0)
48+
#define GO_TO_INSTRUCTION(instname, size) ((void)0)
4949

5050
#define inst(name, ...) case name:
5151
#define op(name, ...) /* NAME is ignored */
@@ -2014,7 +2014,7 @@ dummy_func(
20142014
// cancel out the decrement that will happen in LOAD_SUPER_ATTR; we
20152015
// don't want to specialize instrumented instructions
20162016
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
2017-
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
2017+
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR);
20182018
}
20192019

20202020
family(LOAD_SUPER_ATTR, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
@@ -4313,7 +4313,7 @@ dummy_func(
43134313
frame, this_instr, function, arg);
43144314
ERROR_IF(err, error);
43154315
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
4316-
GO_TO_INSTRUCTION(CALL_KW);
4316+
GO_TO_INSTRUCTION(CALL_KW, INLINE_CACHE_ENTRIES_CALL_KW);
43174317
}
43184318

43194319
op(_MAYBE_EXPAND_METHOD_KW, (callable[1], self_or_null[1], args[oparg], kwnames_in -- func[1], maybe_self[1], args[oparg], kwnames_out)) {
@@ -4539,7 +4539,7 @@ dummy_func(
45394539
_CHECK_PERIODIC;
45404540

45414541
inst(INSTRUMENTED_CALL_FUNCTION_EX, ( -- )) {
4542-
GO_TO_INSTRUCTION(CALL_FUNCTION_EX);
4542+
GO_TO_INSTRUCTION(CALL_FUNCTION_EX, 0);
45434543
}
45444544

45454545
op(_MAKE_CALLARGS_A_TUPLE, (func, unused, callargs, kwargs_in if (oparg & 1) -- func, unused, tuple, kwargs_out if (oparg & 1))) {

Python/ceval_macros.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,18 @@ GETITEM(PyObject *v, Py_ssize_t i) {
326326
PyStackRef_XCLOSE(tmp); } while (0)
327327
#ifdef Py_TAIL_CALL_INTERP
328328
#ifdef LLTRACE
329-
#define GO_TO_INSTRUCTION(op) do { \
329+
#define GO_TO_INSTRUCTION(op, size) do { \
330330
Py_MUSTTAIL \
331-
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - _PyOpcode_Caches[_PyOpcode_Deopt[op]], opcode, oparg, lltrace); \
331+
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - size, opcode, oparg, lltrace); \
332332
} while (0)
333333
#else
334-
#define GO_TO_INSTRUCTION(op) do { \
334+
#define GO_TO_INSTRUCTION(op, size) do { \
335335
Py_MUSTTAIL \
336-
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - _PyOpcode_Caches[_PyOpcode_Deopt[op]], opcode, oparg); \
336+
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - size, opcode, oparg); \
337337
} while (0)
338338
#endif
339339
#else
340-
#define GO_TO_INSTRUCTION(op) goto PREDICT_ID(op)
340+
#define GO_TO_INSTRUCTION(op, size) goto PREDICT_ID(op)
341341
#endif
342342

343343
#ifdef Py_STATS
@@ -354,12 +354,12 @@ GETITEM(PyObject *v, Py_ssize_t i) {
354354
#define UPDATE_MISS_STATS(INSTNAME) ((void)0)
355355
#endif
356356

357-
#define DEOPT_IF(COND, INSTNAME) \
357+
#define DEOPT_IF(COND, INSTNAME, SIZE) \
358358
if ((COND)) { \
359359
/* This is only a single jump on release builds! */ \
360360
UPDATE_MISS_STATS((INSTNAME)); \
361361
assert(_PyOpcode_Deopt[opcode] == (INSTNAME)); \
362-
GO_TO_INSTRUCTION(INSTNAME); \
362+
GO_TO_INSTRUCTION(INSTNAME, SIZE); \
363363
}
364364

365365

0 commit comments

Comments
 (0)