gh-115999: Don't take a reason in unspecialize (#127030)

Don't take a reason in unspecialize

We only want to compute the reason if stats are enabled. Optimizing
compilers should optimize this away for us (gcc and clang do), but
it's better to be safe than sorry.
This commit is contained in:
mpage 2024-11-20 14:54:48 -08:00 committed by GitHub
parent 0af4ec30bd
commit 32428cf9ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

View File

@ -719,7 +719,7 @@ specialize(_Py_CODEUNIT *instr, uint8_t specialized_opcode)
} }
static inline void static inline void
unspecialize(_Py_CODEUNIT *instr, int reason) unspecialize(_Py_CODEUNIT *instr)
{ {
assert(!PyErr_Occurred()); assert(!PyErr_Occurred());
uint8_t opcode = FT_ATOMIC_LOAD_UINT8_RELAXED(instr->op.code); uint8_t opcode = FT_ATOMIC_LOAD_UINT8_RELAXED(instr->op.code);
@ -729,7 +729,6 @@ unspecialize(_Py_CODEUNIT *instr, int reason)
SPECIALIZATION_FAIL(generic_opcode, SPEC_FAIL_OTHER); SPECIALIZATION_FAIL(generic_opcode, SPEC_FAIL_OTHER);
return; return;
} }
SPECIALIZATION_FAIL(generic_opcode, reason);
_Py_BackoffCounter *counter = (_Py_BackoffCounter *)instr + 1; _Py_BackoffCounter *counter = (_Py_BackoffCounter *)instr + 1;
_Py_BackoffCounter cur = load_counter(counter); _Py_BackoffCounter cur = load_counter(counter);
set_counter(counter, adaptive_counter_backoff(cur)); set_counter(counter, adaptive_counter_backoff(cur));
@ -2243,6 +2242,7 @@ _Py_Specialize_CallKw(_PyStackRef callable_st, _Py_CODEUNIT *instr, int nargs)
} }
} }
#ifdef Py_STATS
static int static int
binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs) binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
{ {
@ -2310,6 +2310,7 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
} }
Py_UNREACHABLE(); Py_UNREACHABLE();
} }
#endif
void void
_Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *instr, _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *instr,
@ -2373,7 +2374,8 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
} }
break; break;
} }
unspecialize(instr, binary_op_fail_kind(oparg, lhs, rhs)); SPECIALIZATION_FAIL(BINARY_OP, binary_op_fail_kind(oparg, lhs, rhs));
unspecialize(instr);
} }
@ -2760,6 +2762,7 @@ _Py_Specialize_ToBool(_PyStackRef value_o, _Py_CODEUNIT *instr)
cache->counter = adaptive_counter_cooldown(); cache->counter = adaptive_counter_cooldown();
} }
#ifdef Py_STATS
static int static int
containsop_fail_kind(PyObject *value) { containsop_fail_kind(PyObject *value) {
if (PyUnicode_CheckExact(value)) { if (PyUnicode_CheckExact(value)) {
@ -2776,6 +2779,7 @@ containsop_fail_kind(PyObject *value) {
} }
return SPEC_FAIL_OTHER; return SPEC_FAIL_OTHER;
} }
#endif
void void
_Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr) _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
@ -2793,7 +2797,8 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
return; return;
} }
unspecialize(instr, containsop_fail_kind(value)); SPECIALIZATION_FAIL(CONTAINS_OP, containsop_fail_kind(value));
unspecialize(instr);
return; return;
} }