This commit is contained in:
Tomas R. 2025-12-23 10:03:14 +01:00 committed by GitHub
commit df65b1089f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 1047 additions and 819 deletions

View file

@ -1377,7 +1377,7 @@ _PyOpcode_macro_expansion[256] = {
[CALL_PY_GENERAL] = { .nuops = 6, .uops = { { _CHECK_PEP_523, OPARG_SIMPLE, 1 }, { _CHECK_FUNCTION_VERSION, 2, 1 }, { _CHECK_RECURSION_REMAINING, OPARG_SIMPLE, 3 }, { _PY_FRAME_GENERAL, OPARG_SIMPLE, 3 }, { _SAVE_RETURN_OFFSET, OPARG_SAVE_RETURN_OFFSET, 3 }, { _PUSH_FRAME, OPARG_SIMPLE, 3 } } },
[CALL_STR_1] = { .nuops = 5, .uops = { { _GUARD_NOS_NULL, OPARG_SIMPLE, 3 }, { _GUARD_CALLABLE_STR_1, OPARG_SIMPLE, 3 }, { _CALL_STR_1, OPARG_SIMPLE, 3 }, { _POP_TOP, OPARG_SIMPLE, 3 }, { _CHECK_PERIODIC_AT_END, OPARG_REPLACED, 3 } } },
[CALL_TUPLE_1] = { .nuops = 5, .uops = { { _GUARD_NOS_NULL, OPARG_SIMPLE, 3 }, { _GUARD_CALLABLE_TUPLE_1, OPARG_SIMPLE, 3 }, { _CALL_TUPLE_1, OPARG_SIMPLE, 3 }, { _POP_TOP, OPARG_SIMPLE, 3 }, { _CHECK_PERIODIC_AT_END, OPARG_REPLACED, 3 } } },
[CALL_TYPE_1] = { .nuops = 3, .uops = { { _GUARD_NOS_NULL, OPARG_SIMPLE, 3 }, { _GUARD_CALLABLE_TYPE_1, OPARG_SIMPLE, 3 }, { _CALL_TYPE_1, OPARG_SIMPLE, 3 } } },
[CALL_TYPE_1] = { .nuops = 4, .uops = { { _GUARD_NOS_NULL, OPARG_SIMPLE, 3 }, { _GUARD_CALLABLE_TYPE_1, OPARG_SIMPLE, 3 }, { _CALL_TYPE_1, OPARG_SIMPLE, 3 }, { _POP_TOP, OPARG_SIMPLE, 3 } } },
[CHECK_EG_MATCH] = { .nuops = 1, .uops = { { _CHECK_EG_MATCH, OPARG_SIMPLE, 0 } } },
[CHECK_EXC_MATCH] = { .nuops = 1, .uops = { { _CHECK_EXC_MATCH, OPARG_SIMPLE, 0 } } },
[COMPARE_OP] = { .nuops = 1, .uops = { { _COMPARE_OP, OPARG_SIMPLE, 0 } } },

File diff suppressed because it is too large Load diff

View file

@ -269,7 +269,7 @@ const uint32_t _PyUop_Flags[MAX_UOP_ID+1] = {
[_GUARD_NOS_NOT_NULL] = HAS_EXIT_FLAG,
[_GUARD_THIRD_NULL] = HAS_DEOPT_FLAG,
[_GUARD_CALLABLE_TYPE_1] = HAS_DEOPT_FLAG,
[_CALL_TYPE_1] = HAS_ARG_FLAG | HAS_ESCAPES_FLAG,
[_CALL_TYPE_1] = HAS_ARG_FLAG,
[_GUARD_CALLABLE_STR_1] = HAS_DEOPT_FLAG,
[_CALL_STR_1] = HAS_ARG_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG | HAS_ESCAPES_FLAG,
[_GUARD_CALLABLE_TUPLE_1] = HAS_DEOPT_FLAG,
@ -335,6 +335,7 @@ const uint32_t _PyUop_Flags[MAX_UOP_ID+1] = {
[_POP_TWO_LOAD_CONST_INLINE_BORROW] = HAS_ESCAPES_FLAG,
[_POP_CALL_LOAD_CONST_INLINE_BORROW] = HAS_ESCAPES_FLAG,
[_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW] = HAS_ESCAPES_FLAG,
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW] = 0,
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW] = 0,
[_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = HAS_ESCAPES_FLAG,
[_LOAD_CONST_UNDER_INLINE] = 0,
@ -2473,12 +2474,12 @@ const _PyUopCachingInfo _PyUop_Caching[MAX_UOP_ID+1] = {
},
},
[_CALL_TYPE_1] = {
.best = { 3, 3, 3, 3 },
.best = { 0, 1, 2, 3 },
.entries = {
{ -1, -1, -1 },
{ -1, -1, -1 },
{ -1, -1, -1 },
{ 1, 3, _CALL_TYPE_1_r31 },
{ 2, 0, _CALL_TYPE_1_r02 },
{ 2, 1, _CALL_TYPE_1_r12 },
{ 2, 2, _CALL_TYPE_1_r22 },
{ 2, 3, _CALL_TYPE_1_r32 },
},
},
[_GUARD_CALLABLE_STR_1] = {
@ -3066,6 +3067,15 @@ const _PyUopCachingInfo _PyUop_Caching[MAX_UOP_ID+1] = {
{ 1, 3, _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW_r31 },
},
},
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW] = {
.best = { 0, 1, 2, 3 },
.entries = {
{ 2, 0, _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r02 },
{ 2, 1, _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r12 },
{ 2, 2, _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r22 },
{ 2, 3, _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r32 },
},
},
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW] = {
.best = { 0, 1, 2, 3 },
.entries = {
@ -3698,7 +3708,10 @@ const uint16_t _PyUop_Uncached[MAX_UOP_REGS_ID+1] = {
[_GUARD_CALLABLE_TYPE_1_r13] = _GUARD_CALLABLE_TYPE_1,
[_GUARD_CALLABLE_TYPE_1_r23] = _GUARD_CALLABLE_TYPE_1,
[_GUARD_CALLABLE_TYPE_1_r33] = _GUARD_CALLABLE_TYPE_1,
[_CALL_TYPE_1_r31] = _CALL_TYPE_1,
[_CALL_TYPE_1_r02] = _CALL_TYPE_1,
[_CALL_TYPE_1_r12] = _CALL_TYPE_1,
[_CALL_TYPE_1_r22] = _CALL_TYPE_1,
[_CALL_TYPE_1_r32] = _CALL_TYPE_1,
[_GUARD_CALLABLE_STR_1_r03] = _GUARD_CALLABLE_STR_1,
[_GUARD_CALLABLE_STR_1_r13] = _GUARD_CALLABLE_STR_1,
[_GUARD_CALLABLE_STR_1_r23] = _GUARD_CALLABLE_STR_1,
@ -3829,6 +3842,10 @@ const uint16_t _PyUop_Uncached[MAX_UOP_REGS_ID+1] = {
[_POP_TWO_LOAD_CONST_INLINE_BORROW_r21] = _POP_TWO_LOAD_CONST_INLINE_BORROW,
[_POP_CALL_LOAD_CONST_INLINE_BORROW_r21] = _POP_CALL_LOAD_CONST_INLINE_BORROW,
[_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW_r31] = _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW,
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r02] = _SHUFFLE_2_LOAD_CONST_INLINE_BORROW,
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r12] = _SHUFFLE_2_LOAD_CONST_INLINE_BORROW,
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r22] = _SHUFFLE_2_LOAD_CONST_INLINE_BORROW,
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r32] = _SHUFFLE_2_LOAD_CONST_INLINE_BORROW,
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r03] = _SHUFFLE_3_LOAD_CONST_INLINE_BORROW,
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r13] = _SHUFFLE_3_LOAD_CONST_INLINE_BORROW,
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r23] = _SHUFFLE_3_LOAD_CONST_INLINE_BORROW,
@ -4017,7 +4034,10 @@ const char *const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1] = {
[_CALL_TUPLE_1] = "_CALL_TUPLE_1",
[_CALL_TUPLE_1_r32] = "_CALL_TUPLE_1_r32",
[_CALL_TYPE_1] = "_CALL_TYPE_1",
[_CALL_TYPE_1_r31] = "_CALL_TYPE_1_r31",
[_CALL_TYPE_1_r02] = "_CALL_TYPE_1_r02",
[_CALL_TYPE_1_r12] = "_CALL_TYPE_1_r12",
[_CALL_TYPE_1_r22] = "_CALL_TYPE_1_r22",
[_CALL_TYPE_1_r32] = "_CALL_TYPE_1_r32",
[_CHECK_AND_ALLOCATE_OBJECT] = "_CHECK_AND_ALLOCATE_OBJECT",
[_CHECK_AND_ALLOCATE_OBJECT_r00] = "_CHECK_AND_ALLOCATE_OBJECT_r00",
[_CHECK_ATTR_CLASS] = "_CHECK_ATTR_CLASS",
@ -4780,6 +4800,11 @@ const char *const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1] = {
[_SET_IP_r33] = "_SET_IP_r33",
[_SET_UPDATE] = "_SET_UPDATE",
[_SET_UPDATE_r10] = "_SET_UPDATE_r10",
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW] = "_SHUFFLE_2_LOAD_CONST_INLINE_BORROW",
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r02] = "_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r02",
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r12] = "_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r12",
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r22] = "_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r22",
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r32] = "_SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r32",
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW] = "_SHUFFLE_3_LOAD_CONST_INLINE_BORROW",
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r03] = "_SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r03",
[_SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r13] = "_SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r13",
@ -5502,6 +5527,8 @@ int _PyUop_num_popped(int opcode, int oparg)
return 2;
case _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW:
return 3;
case _SHUFFLE_2_LOAD_CONST_INLINE_BORROW:
return 3;
case _SHUFFLE_3_LOAD_CONST_INLINE_BORROW:
return 3;
case _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW:

View file

@ -1925,9 +1925,10 @@ class TestUopsOptimization(unittest.TestCase):
self.assertIsNotNone(ex)
uops = get_opnames(ex)
# When the result of type(...) is known, _CALL_TYPE_1 is replaced with
# _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW which is optimized away in
# _SHUFFLE_2_LOAD_CONST_INLINE_BORROW which is optimized away in
# remove_unneeded_uops.
self.assertNotIn("_CALL_TYPE_1", uops)
self.assertNotIn("_SHUFFLE_2_LOAD_CONST_INLINE_BORROW", uops)
self.assertNotIn("_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW", uops)
self.assertNotIn("_POP_CALL_LOAD_CONST_INLINE_BORROW", uops)
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
@ -1947,6 +1948,21 @@ class TestUopsOptimization(unittest.TestCase):
uops = get_opnames(ex)
self.assertNotIn("_GUARD_IS_NOT_NONE_POP", uops)
def test_call_type_1_pop_top(self):
def testfunc(n):
x = 0
for _ in range(n):
foo = eval('42')
x += type(foo) is int
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_CALL_TYPE_1", uops)
self.assertIn("_POP_TOP_NOP", uops)
def test_call_tuple_1_pop_top(self):
def testfunc(n):
x = 0

View file

@ -0,0 +1 @@
Eliminate redundant refcounting from ``_CALL_TYPE_1``. Patch by Tomas Roun

View file

@ -3986,17 +3986,14 @@ dummy_func(
DEOPT_IF(callable_o != (PyObject *)&PyType_Type);
}
op(_CALL_TYPE_1, (callable, null, arg -- res)) {
op(_CALL_TYPE_1, (callable, null, arg -- res, a)) {
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
assert(oparg == 1);
DEAD(null);
DEAD(callable);
(void)callable; // Silence compiler warnings about unused variables
(void)null;
STAT_INC(CALL, hit);
INPUTS_DEAD();
res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
PyStackRef_CLOSE(arg);
a = arg;
}
macro(CALL_TYPE_1) =
@ -4004,7 +4001,8 @@ dummy_func(
unused/2 +
_GUARD_NOS_NULL +
_GUARD_CALLABLE_TYPE_1 +
_CALL_TYPE_1;
_CALL_TYPE_1 +
POP_TOP;
op(_GUARD_CALLABLE_STR_1, (callable, unused, unused -- callable, unused, unused)) {
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
@ -5258,6 +5256,12 @@ dummy_func(
value = PyStackRef_FromPyObjectBorrow(ptr);
}
tier2 op(_SHUFFLE_2_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, arg -- res, a)) {
res = PyStackRef_FromPyObjectBorrow(ptr);
a = arg;
INPUTS_DEAD();
}
tier2 op(_SHUFFLE_3_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, arg -- res, a, c)) {
res = PyStackRef_FromPyObjectBorrow(ptr);
a = arg;

View file

@ -12810,38 +12810,94 @@
break;
}
case _CALL_TYPE_1_r31: {
case _CALL_TYPE_1_r02: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
oparg = CURRENT_OPARG();
arg = stack_pointer[-1];
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
assert(oparg == 1);
STAT_INC(CALL, hit);
res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(2);
stack_pointer += -3;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _CALL_TYPE_1_r12: {
CHECK_CURRENT_CACHED_VALUES(1);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
_PyStackRef _stack_item_0 = _tos_cache0;
oparg = CURRENT_OPARG();
arg = _stack_item_0;
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
assert(oparg == 1);
STAT_INC(CALL, hit);
res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(2);
stack_pointer += -2;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _CALL_TYPE_1_r22: {
CHECK_CURRENT_CACHED_VALUES(2);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
_PyStackRef _stack_item_0 = _tos_cache0;
_PyStackRef _stack_item_1 = _tos_cache1;
oparg = CURRENT_OPARG();
arg = _stack_item_1;
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
assert(oparg == 1);
STAT_INC(CALL, hit);
res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(2);
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _CALL_TYPE_1_r32: {
CHECK_CURRENT_CACHED_VALUES(3);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef null;
_PyStackRef callable;
_PyStackRef res;
_PyStackRef a;
_PyStackRef _stack_item_0 = _tos_cache0;
_PyStackRef _stack_item_1 = _tos_cache1;
_PyStackRef _stack_item_2 = _tos_cache2;
oparg = CURRENT_OPARG();
arg = _stack_item_2;
null = _stack_item_1;
callable = _stack_item_0;
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
assert(oparg == 1);
(void)callable;
(void)null;
STAT_INC(CALL, hit);
res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
stack_pointer[0] = res;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(arg);
stack_pointer = _PyFrame_GetStackPointer(frame);
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
_tos_cache1 = PyStackRef_ZERO_BITS;
_tos_cache2 = PyStackRef_ZERO_BITS;
SET_CURRENT_CACHED_VALUES(1);
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
SET_CURRENT_CACHED_VALUES(2);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
@ -16599,6 +16655,86 @@
break;
}
case _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r02: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
arg = stack_pointer[-1];
PyObject *ptr = (PyObject *)CURRENT_OPERAND0_64();
res = PyStackRef_FromPyObjectBorrow(ptr);
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(2);
stack_pointer += -3;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r12: {
CHECK_CURRENT_CACHED_VALUES(1);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
_PyStackRef _stack_item_0 = _tos_cache0;
arg = _stack_item_0;
PyObject *ptr = (PyObject *)CURRENT_OPERAND0_64();
res = PyStackRef_FromPyObjectBorrow(ptr);
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(2);
stack_pointer += -2;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r22: {
CHECK_CURRENT_CACHED_VALUES(2);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
_PyStackRef _stack_item_0 = _tos_cache0;
_PyStackRef _stack_item_1 = _tos_cache1;
arg = _stack_item_1;
PyObject *ptr = (PyObject *)CURRENT_OPERAND0_64();
res = PyStackRef_FromPyObjectBorrow(ptr);
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(2);
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _SHUFFLE_2_LOAD_CONST_INLINE_BORROW_r32: {
CHECK_CURRENT_CACHED_VALUES(3);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
_PyStackRef _stack_item_0 = _tos_cache0;
_PyStackRef _stack_item_1 = _tos_cache1;
_PyStackRef _stack_item_2 = _tos_cache2;
arg = _stack_item_2;
PyObject *ptr = (PyObject *)CURRENT_OPERAND0_64();
res = PyStackRef_FromPyObjectBorrow(ptr);
a = arg;
_tos_cache1 = a;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(2);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _SHUFFLE_3_LOAD_CONST_INLINE_BORROW_r03: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());

View file

@ -4144,6 +4144,8 @@
_PyStackRef callable;
_PyStackRef arg;
_PyStackRef res;
_PyStackRef a;
_PyStackRef value;
/* Skip 1 cache entry */
/* Skip 2 cache entries */
// _GUARD_NOS_NULL
@ -4170,15 +4172,18 @@
arg = stack_pointer[-1];
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
assert(oparg == 1);
(void)callable;
(void)null;
STAT_INC(CALL, hit);
res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
a = arg;
}
// _POP_TOP
{
value = a;
stack_pointer[-3] = res;
stack_pointer += -2;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_CLOSE(arg);
PyStackRef_XCLOSE(value);
stack_pointer = _PyFrame_GetStackPointer(frame);
}
DISPATCH();

View file

@ -446,7 +446,9 @@ const uint16_t op_without_push[MAX_UOP_ID + 1] = {
[_POP_TOP_LOAD_CONST_INLINE] = _POP_TOP,
[_POP_TOP_LOAD_CONST_INLINE_BORROW] = _POP_TOP,
[_POP_TWO_LOAD_CONST_INLINE_BORROW] = _POP_TWO,
[_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW] = _POP_CALL_ONE,
[_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW] = _POP_CALL_TWO,
[_SHUFFLE_2_LOAD_CONST_INLINE_BORROW] = _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW,
};
const bool op_skip[MAX_UOP_ID + 1] = {
@ -458,6 +460,10 @@ const bool op_skip[MAX_UOP_ID + 1] = {
const uint16_t op_without_pop[MAX_UOP_ID + 1] = {
[_POP_TOP] = _NOP,
[_POP_TOP_NOP] = _NOP,
[_POP_TOP_INT] = _NOP,
[_POP_TOP_FLOAT] = _NOP,
[_POP_TOP_UNICODE] = _NOP,
[_POP_TOP_LOAD_CONST_INLINE] = _LOAD_CONST_INLINE,
[_POP_TOP_LOAD_CONST_INLINE_BORROW] = _LOAD_CONST_INLINE_BORROW,
[_POP_TWO] = _POP_TOP,

View file

@ -533,6 +533,11 @@ dummy_func(void) {
value = PyJitRef_Borrow(sym_new_const(ctx, ptr));
}
op(_SHUFFLE_2_LOAD_CONST_INLINE_BORROW, (ptr/4, unused, unused, arg -- res, a)) {
res = PyJitRef_Borrow(sym_new_const(ctx, ptr));
a = arg;
}
op(_POP_TOP, (value -- )) {
PyTypeObject *typ = sym_get_type(value);
if (PyJitRef_IsBorrowed(value) ||
@ -981,16 +986,17 @@ dummy_func(void) {
next = sym_new_type(ctx, &PyLong_Type);
}
op(_CALL_TYPE_1, (unused, unused, arg -- res)) {
op(_CALL_TYPE_1, (unused, unused, arg -- res, a)) {
PyObject* type = (PyObject *)sym_get_type(arg);
if (type) {
res = sym_new_const(ctx, type);
REPLACE_OP(this_instr, _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW, 0,
REPLACE_OP(this_instr, _SHUFFLE_2_LOAD_CONST_INLINE_BORROW, 0,
(uintptr_t)type);
}
else {
res = sym_new_not_null(ctx);
}
a = arg;
}
op(_CALL_STR_1, (unused, unused, arg -- res, a)) {

View file

@ -2680,19 +2680,22 @@
case _CALL_TYPE_1: {
JitOptRef arg;
JitOptRef res;
JitOptRef a;
arg = stack_pointer[-1];
PyObject* type = (PyObject *)sym_get_type(arg);
if (type) {
res = sym_new_const(ctx, type);
REPLACE_OP(this_instr, _POP_CALL_ONE_LOAD_CONST_INLINE_BORROW, 0,
REPLACE_OP(this_instr, _SHUFFLE_2_LOAD_CONST_INLINE_BORROW, 0,
(uintptr_t)type);
}
else {
res = sym_new_not_null(ctx);
}
CHECK_STACK_BOUNDS(-2);
a = arg;
CHECK_STACK_BOUNDS(-1);
stack_pointer[-3] = res;
stack_pointer += -2;
stack_pointer[-2] = a;
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}
@ -3450,6 +3453,22 @@
break;
}
case _SHUFFLE_2_LOAD_CONST_INLINE_BORROW: {
JitOptRef arg;
JitOptRef res;
JitOptRef a;
arg = stack_pointer[-1];
PyObject *ptr = (PyObject *)this_instr->operand0;
res = PyJitRef_Borrow(sym_new_const(ctx, ptr));
a = arg;
CHECK_STACK_BOUNDS(-1);
stack_pointer[-3] = res;
stack_pointer[-2] = a;
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}
case _SHUFFLE_3_LOAD_CONST_INLINE_BORROW: {
JitOptRef res;
JitOptRef a;