Skip to content

Commit 0a7cb9a

Browse files
committed
fix escape && add _STORE_ATTR_INSTANCE_VALUE_NULL
1 parent 8bd0ff9 commit 0a7cb9a

File tree

8 files changed

+1175
-919
lines changed

8 files changed

+1175
-919
lines changed

Include/internal/pycore_uop_ids.h

Lines changed: 899 additions & 894 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,23 @@ dummy_func(
26712671
Py_XDECREF(old_value);
26722672
}
26732673

2674+
op(_STORE_ATTR_INSTANCE_VALUE_NULL, (offset/1, value, owner -- o)) {
2675+
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
2676+
2677+
STAT_INC(STORE_ATTR, hit);
2678+
assert(_PyObject_GetManagedDict(owner_o) == NULL);
2679+
PyObject **value_ptr = (PyObject**)(((char *)owner_o) + offset);
2680+
PyObject *old_value = *value_ptr;
2681+
DEOPT_IF(old_value != NULL);
2682+
FT_ATOMIC_STORE_PTR_RELEASE(*value_ptr, PyStackRef_AsPyObjectSteal(value));
2683+
PyDictValues *values = _PyObject_InlineValues(owner_o);
2684+
Py_ssize_t index = value_ptr - values->values;
2685+
_PyDictValues_AddToInsertionOrder(values, index);
2686+
UNLOCK_OBJECT(owner_o);
2687+
INPUTS_DEAD();
2688+
o = owner;
2689+
}
2690+
26742691
macro(STORE_ATTR_INSTANCE_VALUE) =
26752692
unused/1 +
26762693
_GUARD_TYPE_VERSION_AND_LOCK +

Python/executor_cases.c.h

Lines changed: 141 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_analysis.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,7 @@ optimize_uops(
506506

507507
int oparg = this_instr->oparg;
508508
opcode = this_instr->opcode;
509-
bool was_init_shim = CURRENT_FRAME_IS_INIT_SHIM();
510-
511-
if (!was_init_shim) {
509+
if (!CURRENT_FRAME_IS_INIT_SHIM()) {
512510
stack_pointer = ctx->frame->stack_pointer;
513511
}
514512

@@ -524,14 +522,13 @@ optimize_uops(
524522
DPRINTF(1, "\nUnknown opcode in abstract interpreter\n");
525523
Py_UNREACHABLE();
526524
}
527-
bool is_init_shim = CURRENT_FRAME_IS_INIT_SHIM();
528525
// If no ADD_OP was called during this iteration, copy the original instruction
529526
if (ctx->out_buffer.next == out_ptr) {
530527
*(ctx->out_buffer.next++) = *this_instr;
531528
}
532-
// Track escapes - but skip when in/from init shim frame, since self hasn't escaped yet
533-
if ((_PyUop_Flags[out_ptr->opcode] & HAS_ESCAPES_FLAG) &&
534-
!was_init_shim && !is_init_shim)
529+
// Track escapes - but skip when from init shim frame, since self hasn't escaped yet
530+
bool is_init_shim = CURRENT_FRAME_IS_INIT_SHIM();
531+
if ((_PyUop_Flags[out_ptr->opcode] & HAS_ESCAPES_FLAG) && !is_init_shim)
535532
{
536533
ctx->last_escape_index = uop_buffer_length(&ctx->out_buffer) - 1;
537534
}

Python/optimizer_bytecodes.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ dummy_func(void) {
106106
}
107107

108108
op(_STORE_ATTR_INSTANCE_VALUE, (offset/1, value, owner -- o)) {
109+
JitOptRef old_value = sym_set_attr(ctx, owner, (uint16_t)offset, value);
110+
if (sym_is_null(old_value)) {
111+
ADD_OP(_STORE_ATTR_INSTANCE_VALUE_NULL, 0, offset);
112+
}
113+
o = owner;
114+
}
115+
116+
op(_STORE_ATTR_INSTANCE_VALUE_NULL, (offset/1, value, owner -- o)) {
109117
(void)value;
110118
o = owner;
111119
}
@@ -135,6 +143,11 @@ dummy_func(void) {
135143
o = owner;
136144
}
137145

146+
op(_STORE_ATTR_SLOT_NULL, (index/1, value, owner -- o)) {
147+
(void)value;
148+
o = owner;
149+
}
150+
138151
op(_STORE_SUBSCR_DICT, (value, dict_st, sub -- st)) {
139152
(void)value;
140153
st = dict_st;
@@ -941,7 +954,7 @@ dummy_func(void) {
941954
(void)args;
942955
callable = sym_new_not_null(ctx);
943956
PyTypeObject *tp = _PyType_LookupByVersion(type_version);
944-
if (tp != NULL && tp->tp_basicsize > sizeof(PyObject) && !(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT)) {
957+
if (tp != NULL) {
945958
self_or_null = sym_new_descr_object(ctx, type_version);
946959
} else {
947960
self_or_null = sym_new_not_null(ctx);

Python/optimizer_cases.c.h

Lines changed: 27 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)