Skip to content

Commit 3cedaed

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 d05140f commit 3cedaed

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
@@ -355,6 +355,7 @@ extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int op
355355
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
356356
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
357357
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
358+
extern void _Py_Specialize_LoadConst(PyObject *obj, _Py_CODEUNIT *instr);
358359

359360
#ifdef Py_STATS
360361

Python/specialize.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,18 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
28932893
return;
28942894
}
28952895

2896+
void
2897+
_Py_Specialize_LoadConst(PyObject *obj, _Py_CODEUNIT *instr)
2898+
{
2899+
assert(ENABLE_SPECIALIZATION_FT);
2900+
uint8_t opcode = FT_ATOMIC_LOAD_UINT8_RELAXED(instr->op.code);
2901+
if (opcode == LOAD_CONST) {
2902+
uint8_t spec_opcode =
2903+
_Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
2904+
specialize(instr, spec_opcode);
2905+
}
2906+
}
2907+
28962908
/* Code init cleanup.
28972909
* CALL_ALLOC_AND_ENTER_INIT will set up
28982910
* the frame to execute the EXIT_INIT_CHECK

0 commit comments

Comments
 (0)