Skip to content

Commit d2d0d9e

Browse files
committed
Specialize LOAD_CONST in free-threaded builds
This was previously handled by `_PyCode_Quicken`, but moved to specialization in pythongh-128708. Enable it for the free-threaded build.
1 parent 211f413 commit d2d0d9e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int op
356356
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
357357
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
358358
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
359+
extern void _Py_Specialize_LoadConst(PyObject *obj, _Py_CODEUNIT *instr);
359360

360361
#ifdef Py_STATS
361362

Python/specialize.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,18 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
29942994
return;
29952995
}
29962996

2997+
void
2998+
_Py_Specialize_LoadConst(PyObject *obj, _Py_CODEUNIT *instr)
2999+
{
3000+
assert(ENABLE_SPECIALIZATION_FT);
3001+
uint8_t opcode = FT_ATOMIC_LOAD_UINT8_RELAXED(instr->op.code);
3002+
if (opcode == LOAD_CONST) {
3003+
uint8_t spec_opcode =
3004+
_Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
3005+
specialize(instr, spec_opcode);
3006+
}
3007+
}
3008+
29973009
/* Code init cleanup.
29983010
* CALL_ALLOC_AND_ENTER_INIT will set up
29993011
* the frame to execute the EXIT_INIT_CHECK

0 commit comments

Comments
 (0)