Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a7f317d

Browse filesBrowse files
authored
GH-131798: Add _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW (GH-134268)
1 parent 1fbb060 commit a7f317d
Copy full SHA for a7f317d

File tree

8 files changed

+121
-53
lines changed
Filter options

8 files changed

+121
-53
lines changed

‎Include/internal/pycore_uop_ids.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_uop_ids.h
+42-41Lines changed: 42 additions & 41 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

Copy file name to clipboardExpand all lines: Include/internal/pycore_uop_metadata.h
+4Lines changed: 4 additions & 0 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

Copy file name to clipboardExpand all lines: Lib/test/test_capi/test_opt.py
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,9 +1955,10 @@ def testfunc(n):
19551955
self.assertEqual(res, TIER2_THRESHOLD)
19561956
self.assertIsNotNone(ex)
19571957
uops = get_opnames(ex)
1958-
self.assertIn("_CALL_ISINSTANCE", uops)
1958+
self.assertNotIn("_CALL_ISINSTANCE", uops)
19591959
self.assertNotIn("_GUARD_THIRD_NULL", uops)
19601960
self.assertNotIn("_GUARD_CALLABLE_ISINSTANCE", uops)
1961+
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
19611962

19621963
def test_call_list_append(self):
19631964
def testfunc(n):
@@ -1987,9 +1988,10 @@ def testfunc(n):
19871988
self.assertEqual(res, TIER2_THRESHOLD)
19881989
self.assertIsNotNone(ex)
19891990
uops = get_opnames(ex)
1990-
self.assertIn("_CALL_ISINSTANCE", uops)
1991+
self.assertNotIn("_CALL_ISINSTANCE", uops)
19911992
self.assertNotIn("_TO_BOOL_BOOL", uops)
19921993
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
1994+
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
19931995

19941996
def test_call_isinstance_is_false(self):
19951997
def testfunc(n):
@@ -2004,9 +2006,10 @@ def testfunc(n):
20042006
self.assertEqual(res, TIER2_THRESHOLD)
20052007
self.assertIsNotNone(ex)
20062008
uops = get_opnames(ex)
2007-
self.assertIn("_CALL_ISINSTANCE", uops)
2009+
self.assertNotIn("_CALL_ISINSTANCE", uops)
20082010
self.assertNotIn("_TO_BOOL_BOOL", uops)
20092011
self.assertNotIn("_GUARD_IS_FALSE_POP", uops)
2012+
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
20102013

20112014
def test_call_isinstance_subclass(self):
20122015
def testfunc(n):
@@ -2021,9 +2024,10 @@ def testfunc(n):
20212024
self.assertEqual(res, TIER2_THRESHOLD)
20222025
self.assertIsNotNone(ex)
20232026
uops = get_opnames(ex)
2024-
self.assertIn("_CALL_ISINSTANCE", uops)
2027+
self.assertNotIn("_CALL_ISINSTANCE", uops)
20252028
self.assertNotIn("_TO_BOOL_BOOL", uops)
20262029
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
2030+
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
20272031

20282032
def test_call_isinstance_unknown_object(self):
20292033
def testfunc(n):
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ``_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW`` and use it to further
2+
optimize ``CALL_ISINSTANCE``.

‎Python/bytecodes.c

Copy file name to clipboardExpand all lines: Python/bytecodes.c
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5342,6 +5342,15 @@ dummy_func(
53425342
value = PyStackRef_FromPyObjectImmortal(ptr);
53435343
}
53445344

5345+
tier2 pure op(_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, pop1, pop2 -- value)) {
5346+
PyStackRef_CLOSE(pop2);
5347+
PyStackRef_CLOSE(pop1);
5348+
(void)null; // Silence compiler warnings about unused variables
5349+
DEAD(null);
5350+
PyStackRef_CLOSE(callable);
5351+
value = PyStackRef_FromPyObjectImmortal(ptr);
5352+
}
5353+
53455354
tier2 op(_CHECK_FUNCTION, (func_version/2 -- )) {
53465355
assert(PyStackRef_FunctionCheck(frame->f_funcobj));
53475356
PyFunctionObject *func = (PyFunctionObject *)PyStackRef_AsPyObjectBorrow(frame->f_funcobj);

‎Python/executor_cases.c.h

Copy file name to clipboardExpand all lines: Python/executor_cases.c.h
+34Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Python/optimizer_bytecodes.c

Copy file name to clipboardExpand all lines: Python/optimizer_bytecodes.c
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ dummy_func(void) {
550550
value = sym_new_const(ctx, ptr);
551551
}
552552

553+
op(_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW, (ptr/4, unused, unused, unused, unused -- value)) {
554+
value = sym_new_const(ctx, ptr);
555+
}
556+
553557
op(_COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {
554558
assert(oparg > 0);
555559
top = bottom;
@@ -901,12 +905,12 @@ dummy_func(void) {
901905
// known types, meaning we can deduce either True or False
902906

903907
// The below check is equivalent to PyObject_TypeCheck(inst, cls)
908+
PyObject *out = Py_False;
904909
if (inst_type == cls_o || PyType_IsSubtype(inst_type, cls_o)) {
905-
sym_set_const(res, Py_True);
906-
}
907-
else {
908-
sym_set_const(res, Py_False);
910+
out = Py_True;
909911
}
912+
sym_set_const(res, out);
913+
REPLACE_OP(this_instr, _POP_CALL_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)out);
910914
}
911915
}
912916

‎Python/optimizer_cases.c.h

Copy file name to clipboardExpand all lines: Python/optimizer_cases.c.h
+14-4Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.