Skip to content

Commit a519b87

Browse files
authored
GH-111848: Convert remaining jumps to deopts into tier 2 code. (GH-112045)
1 parent b11c443 commit a519b87

File tree

7 files changed

+184
-129
lines changed

7 files changed

+184
-129
lines changed

Include/internal/pycore_opcode_metadata.h

+87-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_misc.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2610,7 +2610,7 @@ def testfunc(n):
26102610
ex = get_first_executor(testfunc)
26112611
self.assertIsNotNone(ex)
26122612
uops = {opname for opname, _, _ in ex}
2613-
self.assertIn("_POP_JUMP_IF_FALSE", uops)
2613+
self.assertIn("_GUARD_IS_TRUE_POP", uops)
26142614

26152615
def test_pop_jump_if_none(self):
26162616
def testfunc(a):
@@ -2625,7 +2625,7 @@ def testfunc(a):
26252625
ex = get_first_executor(testfunc)
26262626
self.assertIsNotNone(ex)
26272627
uops = {opname for opname, _, _ in ex}
2628-
self.assertIn("_POP_JUMP_IF_TRUE", uops)
2628+
self.assertIn("_GUARD_IS_NOT_NONE_POP", uops)
26292629

26302630
def test_pop_jump_if_not_none(self):
26312631
def testfunc(a):
@@ -2641,7 +2641,7 @@ def testfunc(a):
26412641
ex = get_first_executor(testfunc)
26422642
self.assertIsNotNone(ex)
26432643
uops = {opname for opname, _, _ in ex}
2644-
self.assertIn("_POP_JUMP_IF_FALSE", uops)
2644+
self.assertIn("_GUARD_IS_NONE_POP", uops)
26452645

26462646
def test_pop_jump_if_true(self):
26472647
def testfunc(n):
@@ -2656,7 +2656,7 @@ def testfunc(n):
26562656
ex = get_first_executor(testfunc)
26572657
self.assertIsNotNone(ex)
26582658
uops = {opname for opname, _, _ in ex}
2659-
self.assertIn("_POP_JUMP_IF_TRUE", uops)
2659+
self.assertIn("_GUARD_IS_FALSE_POP", uops)
26602660

26612661
def test_jump_backward(self):
26622662
def testfunc(n):
@@ -2806,7 +2806,7 @@ def testfunc(n):
28062806
ex = get_first_executor(testfunc)
28072807
self.assertIsNotNone(ex)
28082808
uops = {opname for opname, _, _ in ex}
2809-
self.assertIn("_POP_JUMP_IF_TRUE", uops)
2809+
self.assertIn("_GUARD_IS_FALSE_POP", uops)
28102810

28112811

28122812
if __name__ == "__main__":

Python/abstract_interp_cases.c.h

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

+23-12
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ dummy_func(
23682368
goto enter_tier_one;
23692369
}
23702370

2371-
inst(POP_JUMP_IF_FALSE, (unused/1, cond -- )) {
2371+
replaced op(_POP_JUMP_IF_FALSE, (unused/1, cond -- )) {
23722372
assert(PyBool_Check(cond));
23732373
int flag = Py_IsFalse(cond);
23742374
#if ENABLE_SPECIALIZATION
@@ -2377,7 +2377,7 @@ dummy_func(
23772377
JUMPBY(oparg * flag);
23782378
}
23792379

2380-
inst(POP_JUMP_IF_TRUE, (unused/1, cond -- )) {
2380+
replaced op(_POP_JUMP_IF_TRUE, (unused/1, cond -- )) {
23812381
assert(PyBool_Check(cond));
23822382
int flag = Py_IsTrue(cond);
23832383
#if ENABLE_SPECIALIZATION
@@ -2396,9 +2396,13 @@ dummy_func(
23962396
}
23972397
}
23982398

2399-
macro(POP_JUMP_IF_NONE) = _IS_NONE + POP_JUMP_IF_TRUE;
2399+
macro(POP_JUMP_IF_TRUE) = _POP_JUMP_IF_TRUE;
24002400

2401-
macro(POP_JUMP_IF_NOT_NONE) = _IS_NONE + POP_JUMP_IF_FALSE;
2401+
macro(POP_JUMP_IF_FALSE) = _POP_JUMP_IF_FALSE;
2402+
2403+
macro(POP_JUMP_IF_NONE) = _IS_NONE + _POP_JUMP_IF_TRUE;
2404+
2405+
macro(POP_JUMP_IF_NOT_NONE) = _IS_NONE + _POP_JUMP_IF_FALSE;
24022406

24032407
inst(JUMP_BACKWARD_NO_INTERRUPT, (--)) {
24042408
/* This bytecode is used in the `yield from` or `await` loop.
@@ -3963,16 +3967,23 @@ dummy_func(
39633967

39643968
///////// Tier-2 only opcodes /////////
39653969

3966-
op(_POP_JUMP_IF_FALSE, (flag -- )) {
3967-
if (Py_IsFalse(flag)) {
3968-
next_uop = current_executor->trace + oparg;
3969-
}
3970+
op (_GUARD_IS_TRUE_POP, (flag -- )) {
3971+
DEOPT_IF(Py_IsFalse(flag));
3972+
assert(Py_IsTrue(flag));
39703973
}
39713974

3972-
op(_POP_JUMP_IF_TRUE, (flag -- )) {
3973-
if (Py_IsTrue(flag)) {
3974-
next_uop = current_executor->trace + oparg;
3975-
}
3975+
op (_GUARD_IS_FALSE_POP, (flag -- )) {
3976+
DEOPT_IF(Py_IsTrue(flag));
3977+
assert(Py_IsFalse(flag));
3978+
}
3979+
3980+
op (_GUARD_IS_NONE_POP, (val -- )) {
3981+
DEOPT_IF(!Py_IsNone(val));
3982+
}
3983+
3984+
op (_GUARD_IS_NOT_NONE_POP, (val -- )) {
3985+
DEOPT_IF(Py_IsNone(val));
3986+
Py_DECREF(val);
39763987
}
39773988

39783989
op(_JUMP_TO_TOP, (--)) {

0 commit comments

Comments
 (0)