Skip to content

Commit 1e94a6c

Browse files
committed
gh-148211: decompose _INSERT_1_LOAD_CONST_INLINE(_BORROW) in JIT
1 parent b94db0b commit 1e94a6c

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

Python/optimizer_analysis.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ optimize_to_bool(
319319
JitOptContext *ctx,
320320
JitOptRef value,
321321
JitOptRef *result_ptr,
322-
uint16_t prefix, uint16_t load_op, uint16_t suffix)
322+
uint16_t prefix, uint16_t suffix)
323323
{
324324
if (sym_matches_type(value, &PyBool_Type)) {
325325
ADD_OP(_NOP, 0, 0);
@@ -332,7 +332,7 @@ optimize_to_bool(
332332
if (prefix != _NOP) {
333333
ADD_OP(prefix, 0, 0);
334334
}
335-
ADD_OP(load_op, 0, (uintptr_t)load);
335+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
336336
if (suffix != _NOP) {
337337
ADD_OP(suffix, 2, 0);
338338
}
@@ -382,7 +382,7 @@ eliminate_pop_guard(_PyUOpInstruction *this_instr, JitOptContext *ctx, bool exit
382382
static JitOptRef
383383
lookup_attr(JitOptContext *ctx, _PyBloomFilter *dependencies, _PyUOpInstruction *this_instr,
384384
PyTypeObject *type, PyObject *name,
385-
uint16_t prefix, uint16_t immortal_op, uint16_t mortal_op, uint16_t suffix)
385+
uint16_t prefix, uint16_t suffix)
386386
{
387387
// The cached value may be dead, so we need to do the lookup again... :(
388388
if (type && PyType_Check(type)) {
@@ -392,7 +392,8 @@ lookup_attr(JitOptContext *ctx, _PyBloomFilter *dependencies, _PyUOpInstruction
392392
if (prefix != _NOP) {
393393
ADD_OP(prefix, 0, 0);
394394
}
395-
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);
396397
if (suffix != _NOP) {
397398
ADD_OP(suffix, 2, 0);
398399
}

Python/optimizer_bytecodes.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ optimize_to_bool(
5555
JitOptContext *ctx,
5656
JitOptSymbol *value,
5757
JitOptSymbol **result_ptr,
58-
uint16_t prefix, uint16_t load_op, uint16_t suffix);
58+
uint16_t prefix, uint16_t suffix);
5959

6060
extern void
6161
eliminate_pop_guard(_PyUOpInstruction *this_instr, JitOptContext *ctx, bool exit);
@@ -537,23 +537,23 @@ dummy_func(void) {
537537

538538
op(_TO_BOOL, (value -- res)) {
539539
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
540-
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _NOP);
540+
_POP_TOP, _NOP);
541541
if (!already_bool) {
542542
res = sym_new_truthiness(ctx, value, true);
543543
}
544544
}
545545

546546
op(_TO_BOOL_BOOL, (value -- value)) {
547547
int already_bool = optimize_to_bool(this_instr, ctx, value, &value,
548-
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _NOP);
548+
_POP_TOP, _NOP);
549549
if (!already_bool) {
550550
sym_set_type(value, &PyBool_Type);
551551
}
552552
}
553553

554554
op(_TO_BOOL_INT, (value -- res, v)) {
555555
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
556-
_NOP, _LOAD_CONST_INLINE_BORROW, _SWAP);
556+
_NOP, _SWAP);
557557
if (!already_bool) {
558558
sym_set_type(value, &PyLong_Type);
559559
res = sym_new_truthiness(ctx, value, true);
@@ -563,7 +563,7 @@ dummy_func(void) {
563563

564564
op(_TO_BOOL_LIST, (value -- res, v)) {
565565
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
566-
_NOP, _LOAD_CONST_INLINE_BORROW, _SWAP);
566+
_NOP, _SWAP);
567567
if (!already_bool) {
568568
res = sym_new_type(ctx, &PyBool_Type);
569569
}
@@ -572,7 +572,7 @@ dummy_func(void) {
572572

573573
op(_TO_BOOL_NONE, (value -- res)) {
574574
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
575-
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _NOP);
575+
_POP_TOP, _NOP);
576576
if (!already_bool) {
577577
sym_set_const(value, Py_None);
578578
res = sym_new_const(ctx, Py_False);
@@ -599,7 +599,7 @@ dummy_func(void) {
599599

600600
op(_TO_BOOL_STR, (value -- res, v)) {
601601
int already_bool = optimize_to_bool(this_instr, ctx, value, &res,
602-
_NOP, _LOAD_CONST_INLINE_BORROW, _SWAP);
602+
_NOP, _SWAP);
603603
v = value;
604604
if (!already_bool) {
605605
res = sym_new_truthiness(ctx, value, true);
@@ -900,31 +900,31 @@ dummy_func(void) {
900900
PyTypeObject *type = (PyTypeObject *)sym_get_const(ctx, owner);
901901
PyObject *name = get_co_name(ctx, oparg >> 1);
902902
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
903-
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE, _NOP);
903+
_POP_TOP, _NOP);
904904
}
905905

906906
op(_LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES, (descr/4, owner -- attr)) {
907907
(void)descr;
908908
PyTypeObject *type = sym_get_type(owner);
909909
PyObject *name = get_co_name(ctx, oparg >> 1);
910910
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
911-
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE, _NOP);
911+
_POP_TOP, _NOP);
912912
}
913913

914914
op(_LOAD_ATTR_NONDESCRIPTOR_NO_DICT, (descr/4, owner -- attr)) {
915915
(void)descr;
916916
PyTypeObject *type = sym_get_type(owner);
917917
PyObject *name = get_co_name(ctx, oparg >> 1);
918918
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
919-
_POP_TOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE, _NOP);
919+
_POP_TOP, _NOP);
920920
}
921921

922922
op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self)) {
923923
(void)descr;
924924
PyTypeObject *type = sym_get_type(owner);
925925
PyObject *name = get_co_name(ctx, oparg >> 1);
926926
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
927-
_NOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE, _SWAP);
927+
_NOP, _SWAP);
928928
self = owner;
929929
}
930930

@@ -933,7 +933,7 @@ dummy_func(void) {
933933
PyTypeObject *type = sym_get_type(owner);
934934
PyObject *name = get_co_name(ctx, oparg >> 1);
935935
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
936-
_NOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE, _SWAP);
936+
_NOP, _SWAP);
937937
self = owner;
938938
}
939939

@@ -942,7 +942,7 @@ dummy_func(void) {
942942
PyTypeObject *type = sym_get_type(owner);
943943
PyObject *name = get_co_name(ctx, oparg >> 1);
944944
attr = lookup_attr(ctx, dependencies, this_instr, type, name,
945-
_NOP, _LOAD_CONST_INLINE_BORROW, _LOAD_CONST_INLINE, _SWAP);
945+
_NOP, _SWAP);
946946
self = owner;
947947
}
948948

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)