Skip to content

Commit 0f49232

Browse files
authored
gh-148211: decompose _INSERT_1_LOAD_CONST_INLINE(_BORROW) in JIT (GH-148283)
1 parent d8c5658 commit 0f49232

File tree

9 files changed

+1182
-1372
lines changed

9 files changed

+1182
-1372
lines changed

Include/internal/pycore_uop_ids.h

Lines changed: 1106 additions & 1114 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: 0 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,8 +3210,7 @@ def f(n):
32103210
self.assertEqual(res, TIER2_THRESHOLD)
32113211
uops = get_opnames(ex)
32123212
self.assertNotIn("_LOAD_ATTR_METHOD_NO_DICT", uops)
3213-
self.assertNotIn("_INSERT_1_LOAD_CONST_INLINE", uops)
3214-
self.assertIn("_INSERT_1_LOAD_CONST_INLINE_BORROW", uops)
3213+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
32153214

32163215
def test_store_fast_refcount_elimination(self):
32173216
def foo(x):

Python/bytecodes.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5951,18 +5951,6 @@ dummy_func(
59515951
value = PyStackRef_FromPyObjectBorrow(ptr);
59525952
}
59535953

5954-
tier2 op(_INSERT_1_LOAD_CONST_INLINE, (ptr/4, left -- res, l)) {
5955-
res = PyStackRef_FromPyObjectNew(ptr);
5956-
l = left;
5957-
INPUTS_DEAD();
5958-
}
5959-
5960-
tier2 op(_INSERT_1_LOAD_CONST_INLINE_BORROW, (ptr/4, left -- res, l)) {
5961-
res = PyStackRef_FromPyObjectBorrow(ptr);
5962-
l = left;
5963-
INPUTS_DEAD();
5964-
}
5965-
59665954
tier2 op(_INSERT_2_LOAD_CONST_INLINE_BORROW, (ptr/4, left, right -- res, l, r)) {
59675955
res = PyStackRef_FromPyObjectBorrow(ptr);
59685956
l = left;

Python/executor_cases.c.h

Lines changed: 0 additions & 114 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: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ type_watcher_callback(PyTypeObject* type)
156156
}
157157

158158
static PyObject *
159-
convert_global_to_const(_PyUOpInstruction *inst, PyObject *obj,
160-
uint16_t immortal_op, uint16_t mortal_op)
159+
convert_global_to_const(_PyUOpInstruction *inst, PyObject *obj)
161160
{
162161
assert(inst->opcode == _LOAD_GLOBAL_MODULE || inst->opcode == _LOAD_GLOBAL_BUILTINS || inst->opcode == _LOAD_ATTR_MODULE);
163162
assert(PyDict_CheckExact(obj));
@@ -178,15 +177,9 @@ convert_global_to_const(_PyUOpInstruction *inst, PyObject *obj,
178177
return NULL;
179178
}
180179
if (_Py_IsImmortal(res)) {
181-
inst->opcode = immortal_op;
180+
inst->opcode = _LOAD_CONST_INLINE_BORROW;
182181
} else {
183-
inst->opcode = mortal_op;
184-
}
185-
if (inst->opcode == _LOAD_CONST_INLINE_BORROW || inst->opcode == _LOAD_CONST_INLINE) {
186-
if (inst->oparg & 1) {
187-
assert(inst[1].opcode == _PUSH_NULL_CONDITIONAL);
188-
assert(inst[1].oparg & 1);
189-
}
182+
inst->opcode = _LOAD_CONST_INLINE;
190183
}
191184
inst->operand0 = (uint64_t)res;
192185
return res;
@@ -326,7 +319,7 @@ optimize_to_bool(
326319
JitOptContext *ctx,
327320
JitOptRef value,
328321
JitOptRef *result_ptr,
329-
uint16_t prefix, uint16_t load_op)
322+
uint16_t prefix, uint16_t suffix)
330323
{
331324
if (sym_matches_type(value, &PyBool_Type)) {
332325
ADD_OP(_NOP, 0, 0);
@@ -339,7 +332,10 @@ optimize_to_bool(
339332
if (prefix != _NOP) {
340333
ADD_OP(prefix, 0, 0);
341334
}
342-
ADD_OP(load_op, 0, (uintptr_t)load);
335+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
336+
if (suffix != _NOP) {
337+
ADD_OP(suffix, 2, 0);
338+
}
343339
*result_ptr = sym_new_const(ctx, load);
344340
return 1;
345341
}
@@ -386,7 +382,7 @@ eliminate_pop_guard(_PyUOpInstruction *this_instr, JitOptContext *ctx, bool exit
386382
static JitOptRef
387383
lookup_attr(JitOptContext *ctx, _PyBloomFilter *dependencies, _PyUOpInstruction *this_instr,
388384
PyTypeObject *type, PyObject *name,
389-
uint16_t prefix, uint16_t immortal_op, uint16_t mortal_op)
385+
uint16_t prefix, uint16_t suffix)
390386
{
391387
// The cached value may be dead, so we need to do the lookup again... :(
392388
if (type && PyType_Check(type)) {
@@ -396,7 +392,11 @@ lookup_attr(JitOptContext *ctx, _PyBloomFilter *dependencies, _PyUOpInstruction
396392
if (prefix != _NOP) {
397393
ADD_OP(prefix, 0, 0);
398394
}
399-
ADD_OP(immortal ? immortal_op : mortal_op, 0, (uintptr_t)lookup);
395+
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE,
396+
0, (uintptr_t)lookup);
397+
if (suffix != _NOP) {
398+
ADD_OP(suffix, 2, 0);
399+
}
400400
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
401401
_Py_BloomFilter_Add(dependencies, type);
402402
return sym_new_const(ctx, lookup);
@@ -411,7 +411,8 @@ static JitOptRef
411411
lookup_super_attr(JitOptContext *ctx, _PyBloomFilter *dependencies,
412412
_PyUOpInstruction *this_instr,
413413
PyTypeObject *su_type, PyTypeObject *obj_type,
414-
PyObject *name, uint16_t immortal, uint16_t mortal)
414+
PyObject *name,
415+
uint16_t immortal, uint16_t mortal, uint16_t suffix)
415416
{
416417
if (su_type == NULL || obj_type == NULL) {
417418
return sym_new_not_null(ctx);
@@ -439,6 +440,9 @@ lookup_super_attr(JitOptContext *ctx, _PyBloomFilter *dependencies,
439440
ADD_OP(_POP_TOP, 0, 0);
440441
ADD_OP(_POP_TOP, 0, 0);
441442
ADD_OP(opcode, 0, (uintptr_t)lookup);
443+
if (suffix != _NOP) {
444+
ADD_OP(suffix, 2, 0);
445+
}
442446
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)su_type);
443447
_Py_BloomFilter_Add(dependencies, su_type);
444448
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)obj_type);
@@ -647,8 +651,6 @@ const uint16_t op_without_push[MAX_UOP_ID + 1] = {
647651
[_COPY] = _NOP,
648652
[_LOAD_CONST_INLINE] = _NOP,
649653
[_LOAD_CONST_INLINE_BORROW] = _NOP,
650-
[_INSERT_1_LOAD_CONST_INLINE] = _POP_TOP_LOAD_CONST_INLINE,
651-
[_INSERT_1_LOAD_CONST_INLINE_BORROW] = _POP_TOP_LOAD_CONST_INLINE_BORROW,
652654
[_LOAD_FAST] = _NOP,
653655
[_LOAD_FAST_BORROW] = _NOP,
654656
[_LOAD_SMALL_INT] = _NOP,

0 commit comments

Comments
 (0)