Skip to content

Commit c3c6254

Browse files
committed
Simplify
1 parent 0fb391a commit c3c6254

File tree

4 files changed

+49
-43
lines changed

4 files changed

+49
-43
lines changed

Python/optimizer_analysis.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,13 @@ add_op(JitOptContext *ctx, _PyUOpInstruction *this_instr,
234234
out->format = this_instr->format;
235235
out->oparg = (oparg);
236236
out->target = this_instr->target;
237-
out->operand0 = (operand0);
237+
if (opcode == _LOAD_CONST_INLINE_BORROW ||
238+
opcode == _SHUFFLE_3_LOAD_CONST_INLINE_BORROW) {
239+
out->operand0 = PyStackRef_TagBorrow((PyObject *)operand0);
240+
}
241+
else {
242+
out->operand0 = (operand0);
243+
}
238244
out->operand1 = this_instr->operand1;
239245
ctx->out_buffer.next++;
240246
}
@@ -333,7 +339,7 @@ optimize_to_bool(
333339
if (prefix != _NOP) {
334340
ADD_OP(prefix, 0, 0);
335341
}
336-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(load));
342+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
337343
if (suffix != _NOP) {
338344
ADD_OP(suffix, 2, 0);
339345
}
@@ -394,7 +400,7 @@ lookup_attr(JitOptContext *ctx, _PyBloomFilter *dependencies, _PyUOpInstruction
394400
ADD_OP(prefix, 0, 0);
395401
}
396402
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE,
397-
0, immortal ? PyStackRef_TagBorrow(lookup) : (uintptr_t)lookup);
403+
0, (uintptr_t)lookup);
398404
if (suffix != _NOP) {
399405
ADD_OP(suffix, 2, 0);
400406
}
@@ -465,7 +471,7 @@ lookup_super_attr(JitOptContext *ctx, _PyBloomFilter *dependencies,
465471
ADD_OP(_SWAP, 3, 0);
466472
ADD_OP(_POP_TOP, 0, 0);
467473
ADD_OP(_POP_TOP, 0, 0);
468-
ADD_OP(opcode, 0, (opcode == immortal) ? PyStackRef_TagBorrow(lookup) : (uintptr_t)lookup);
474+
ADD_OP(opcode, 0, (uintptr_t)lookup);
469475
if (suffix != _NOP) {
470476
ADD_OP(suffix, 2, 0);
471477
}

Python/optimizer_bytecodes.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -866,22 +866,22 @@ dummy_func(void) {
866866
op(_LOAD_CONST, (-- value)) {
867867
PyCodeObject *co = get_current_code_object(ctx);
868868
PyObject *val = PyTuple_GET_ITEM(co->co_consts, oparg);
869-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(val));
869+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
870870
value = PyJitRef_Borrow(sym_new_const(ctx, val));
871871
}
872872

873873
op(_LOAD_COMMON_CONSTANT, (-- value)) {
874874
assert(oparg < NUM_COMMON_CONSTANTS);
875875
PyObject *val = _PyInterpreterState_GET()->common_consts[oparg];
876-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(val));
876+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
877877
value = PyJitRef_Borrow(sym_new_const(ctx, val));
878878
}
879879

880880
op(_LOAD_SMALL_INT, (-- value)) {
881881
PyObject *val = PyLong_FromLong(oparg);
882882
assert(val);
883883
assert(_Py_IsImmortal(val));
884-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(val));
884+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
885885
value = PyJitRef_Borrow(sym_new_const(ctx, val));
886886
}
887887

@@ -959,7 +959,7 @@ dummy_func(void) {
959959
else {
960960
bool immortal = _Py_IsImmortal(res);
961961
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE,
962-
0, immortal ? PyStackRef_TagBorrow(res) : (uintptr_t)res);
962+
0, (uintptr_t)res);
963963
ADD_OP(_SWAP, 2, 0);
964964
attr = sym_new_const(ctx, res);
965965
}
@@ -1600,7 +1600,7 @@ dummy_func(void) {
16001600
ADD_OP(_SWAP, 3, 0);
16011601
optimize_pop_top(ctx, this_instr, callable);
16021602
optimize_pop_top(ctx, this_instr, null);
1603-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(type));
1603+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)type);
16041604
ADD_OP(_SWAP, 2, 0);
16051605
}
16061606
else {
@@ -1642,7 +1642,7 @@ dummy_func(void) {
16421642
optimize_pop_top(ctx, this_instr, instance);
16431643
optimize_pop_top(ctx, this_instr, null);
16441644
optimize_pop_top(ctx, this_instr, callable);
1645-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(out));
1645+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out);
16461646
}
16471647
}
16481648

@@ -2013,7 +2013,7 @@ dummy_func(void) {
20132013
ADD_OP(_GUARD_TYPE_VERSION, 0, type->tp_version_tag);
20142014
bool immortal = _Py_IsImmortal(descr) || (type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE);
20152015
ADD_OP(immortal ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE,
2016-
0, immortal ? PyStackRef_TagBorrow(descr) : (uintptr_t)descr);
2016+
0, (uintptr_t)descr);
20172017
ADD_OP(_SWAP, 3, 0);
20182018
optimize_pop_top(ctx, this_instr, method_and_self[0]);
20192019
if ((type->tp_flags & Py_TPFLAGS_IMMUTABLETYPE) == 0) {
@@ -2044,7 +2044,7 @@ dummy_func(void) {
20442044
}
20452045

20462046
op(_REPLACE_WITH_TRUE, (value -- res, v)) {
2047-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(Py_True));
2047+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_True);
20482048
ADD_OP(_SWAP, 2, 0);
20492049
res = sym_new_const(ctx, Py_True);
20502050
v = value;
@@ -2330,7 +2330,7 @@ dummy_func(void) {
23302330
goto error;
23312331
}
23322332
if (_Py_IsImmortal(temp)) {
2333-
ADD_OP(_SHUFFLE_3_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(temp));
2333+
ADD_OP(_SHUFFLE_3_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)temp);
23342334
}
23352335
res = sym_new_const(ctx, temp);
23362336
Py_DECREF(temp);
@@ -2351,7 +2351,7 @@ dummy_func(void) {
23512351
goto error;
23522352
}
23532353
if (_Py_IsImmortal(temp)) {
2354-
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, PyStackRef_TagBorrow(temp));
2354+
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)temp);
23552355
}
23562356
len = sym_new_const(ctx, temp);
23572357
Py_DECREF(temp);

Python/optimizer_cases.c.h

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

Tools/cases_generator/optimizer_generator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,23 @@ def replace_opcode_if_evaluates_pure(
241241
# (a -- res), usually for unary ops
242242
0: [("_POP_TOP", "0, 0"),
243243
("_LOAD_CONST_INLINE_BORROW",
244-
"0, PyStackRef_TagBorrow(result)")],
244+
"0, (uintptr_t)result")],
245245
# (left -- res, left)
246246
# usually for unary ops with passthrough references
247247
1: [("_LOAD_CONST_INLINE_BORROW",
248-
"0, PyStackRef_TagBorrow(result)"),
248+
"0, (uintptr_t)result"),
249249
("_SWAP", "2, 0")],
250250
},
251251
2: {
252252
# (a, b -- res), usually for binary ops
253253
0: [("_POP_TOP", "0, 0"),
254254
("_POP_TOP", "0, 0"),
255255
("_LOAD_CONST_INLINE_BORROW",
256-
"0, PyStackRef_TagBorrow(result)")],
256+
"0, (uintptr_t)result")],
257257
# (left, right -- res, left, right)
258258
# usually for binary ops with passthrough references
259259
2: [("_LOAD_CONST_INLINE_BORROW",
260-
"0, PyStackRef_TagBorrow(result)"),
260+
"0, (uintptr_t)result"),
261261
("_SWAP", "3, 0"),
262262
("_SWAP", "2, 0")],
263263
},

0 commit comments

Comments
 (0)