Skip to content

Commit

Permalink
Specialize LOAD_CONST in free-threaded builds
Browse files Browse the repository at this point in the history
This was previously handled by `_PyCode_Quicken`, but moved to specialization
in pythongh-128708. Enable it for the free-threaded build.
  • Loading branch information
mpage committed Jan 15, 2025
1 parent d05140f commit 3cedaed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int op
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
extern void _Py_Specialize_LoadConst(PyObject *obj, _Py_CODEUNIT *instr);

#ifdef Py_STATS

Expand Down
12 changes: 12 additions & 0 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2893,6 +2893,18 @@ _Py_Specialize_ContainsOp(_PyStackRef value_st, _Py_CODEUNIT *instr)
return;
}

void
_Py_Specialize_LoadConst(PyObject *obj, _Py_CODEUNIT *instr)
{
assert(ENABLE_SPECIALIZATION_FT);
uint8_t opcode = FT_ATOMIC_LOAD_UINT8_RELAXED(instr->op.code);
if (opcode == LOAD_CONST) {
uint8_t spec_opcode =
_Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
specialize(instr, spec_opcode);
}
}

/* Code init cleanup.
* CALL_ALLOC_AND_ENTER_INIT will set up
* the frame to execute the EXIT_INIT_CHECK
Expand Down

0 comments on commit 3cedaed

Please sign in to comment.