Skip to content

Commit 982c51d

Browse files
Make deopt more efficient
1 parent fc91ac8 commit 982c51d

File tree

5 files changed

+461
-460
lines changed

5 files changed

+461
-460
lines changed

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 */
@@ -1942,7 +1942,7 @@ dummy_func(
19421942
// cancel out the decrement that will happen in LOAD_SUPER_ATTR; we
19431943
// don't want to specialize instrumented instructions
19441944
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
1945-
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
1945+
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR, INSTRUCTION_SIZE);
19461946
}
19471947

19481948
family(LOAD_SUPER_ATTR, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
@@ -4255,7 +4255,7 @@ dummy_func(
42554255
frame, this_instr, function, arg);
42564256
ERROR_IF(err, error);
42574257
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
4258-
GO_TO_INSTRUCTION(CALL_KW);
4258+
GO_TO_INSTRUCTION(CALL_KW, INSTRUCTION_SIZE);
42594259
}
42604260

42614261
op(_MAYBE_EXPAND_METHOD_KW, (callable[1], self_or_null[1], args[oparg], kwnames_in -- func[1], maybe_self[1], args[oparg], kwnames_out)) {
@@ -4488,7 +4488,7 @@ dummy_func(
44884488
_CHECK_PERIODIC;
44894489

44904490
inst(INSTRUMENTED_CALL_FUNCTION_EX, ( -- )) {
4491-
GO_TO_INSTRUCTION(CALL_FUNCTION_EX);
4491+
GO_TO_INSTRUCTION(CALL_FUNCTION_EX, INSTRUCTION_SIZE);
44924492
}
44934493

44944494
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,14 @@ GETITEM(PyObject *v, Py_ssize_t i) {
325325
PyStackRef_XCLOSE(tmp); } while (0)
326326
#ifdef Py_TAIL_CALL_INTERP
327327
#ifdef LLTRACE
328-
#define GO_TO_INSTRUCTION(op) do { \
328+
#define GO_TO_INSTRUCTION(op, SIZE) do { \
329329
Py_MUSTTAIL \
330-
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - _PyOpcode_Caches[_PyOpcode_Deopt[op]], oparg, entry_frame, lltrace); \
330+
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - SIZE, oparg, entry_frame, lltrace); \
331331
} while (0)
332332
#else
333-
#define GO_TO_INSTRUCTION(op) do { \
333+
#define GO_TO_INSTRUCTION(op, SIZE) do { \
334334
Py_MUSTTAIL \
335-
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - _PyOpcode_Caches[_PyOpcode_Deopt[op]], oparg, entry_frame); \
335+
return (INSTRUCTION_TABLE[op])(frame, stack_pointer, tstate, next_instr - 1 - SIZE, oparg, entry_frame); \
336336
} while (0)
337337
#endif
338338
#else
@@ -353,12 +353,12 @@ GETITEM(PyObject *v, Py_ssize_t i) {
353353
#define UPDATE_MISS_STATS(INSTNAME) ((void)0)
354354
#endif
355355

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

364364

0 commit comments

Comments
 (0)