Skip to content

Commit

Permalink
pythonGH-111848: Convert remaining jumps to deopts into tier 2 code. (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored Nov 14, 2023
1 parent b11c443 commit a519b87
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 129 deletions.
142 changes: 87 additions & 55 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,7 @@ def testfunc(n):
ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
self.assertIn("_POP_JUMP_IF_FALSE", uops)
self.assertIn("_GUARD_IS_TRUE_POP", uops)

def test_pop_jump_if_none(self):
def testfunc(a):
Expand All @@ -2625,7 +2625,7 @@ def testfunc(a):
ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
self.assertIn("_POP_JUMP_IF_TRUE", uops)
self.assertIn("_GUARD_IS_NOT_NONE_POP", uops)

def test_pop_jump_if_not_none(self):
def testfunc(a):
Expand All @@ -2641,7 +2641,7 @@ def testfunc(a):
ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
self.assertIn("_POP_JUMP_IF_FALSE", uops)
self.assertIn("_GUARD_IS_NONE_POP", uops)

def test_pop_jump_if_true(self):
def testfunc(n):
Expand All @@ -2656,7 +2656,7 @@ def testfunc(n):
ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
self.assertIn("_POP_JUMP_IF_TRUE", uops)
self.assertIn("_GUARD_IS_FALSE_POP", uops)

def test_jump_backward(self):
def testfunc(n):
Expand Down Expand Up @@ -2806,7 +2806,7 @@ def testfunc(n):
ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
self.assertIn("_POP_JUMP_IF_TRUE", uops)
self.assertIn("_GUARD_IS_FALSE_POP", uops)


if __name__ == "__main__":
Expand Down
14 changes: 12 additions & 2 deletions Python/abstract_interp_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 23 additions & 12 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,7 @@ dummy_func(
goto enter_tier_one;
}

inst(POP_JUMP_IF_FALSE, (unused/1, cond -- )) {
replaced op(_POP_JUMP_IF_FALSE, (unused/1, cond -- )) {
assert(PyBool_Check(cond));
int flag = Py_IsFalse(cond);
#if ENABLE_SPECIALIZATION
Expand All @@ -2377,7 +2377,7 @@ dummy_func(
JUMPBY(oparg * flag);
}

inst(POP_JUMP_IF_TRUE, (unused/1, cond -- )) {
replaced op(_POP_JUMP_IF_TRUE, (unused/1, cond -- )) {
assert(PyBool_Check(cond));
int flag = Py_IsTrue(cond);
#if ENABLE_SPECIALIZATION
Expand All @@ -2396,9 +2396,13 @@ dummy_func(
}
}

macro(POP_JUMP_IF_NONE) = _IS_NONE + POP_JUMP_IF_TRUE;
macro(POP_JUMP_IF_TRUE) = _POP_JUMP_IF_TRUE;

macro(POP_JUMP_IF_NOT_NONE) = _IS_NONE + POP_JUMP_IF_FALSE;
macro(POP_JUMP_IF_FALSE) = _POP_JUMP_IF_FALSE;

macro(POP_JUMP_IF_NONE) = _IS_NONE + _POP_JUMP_IF_TRUE;

macro(POP_JUMP_IF_NOT_NONE) = _IS_NONE + _POP_JUMP_IF_FALSE;

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

///////// Tier-2 only opcodes /////////

op(_POP_JUMP_IF_FALSE, (flag -- )) {
if (Py_IsFalse(flag)) {
next_uop = current_executor->trace + oparg;
}
op (_GUARD_IS_TRUE_POP, (flag -- )) {
DEOPT_IF(Py_IsFalse(flag));
assert(Py_IsTrue(flag));
}

op(_POP_JUMP_IF_TRUE, (flag -- )) {
if (Py_IsTrue(flag)) {
next_uop = current_executor->trace + oparg;
}
op (_GUARD_IS_FALSE_POP, (flag -- )) {
DEOPT_IF(Py_IsTrue(flag));
assert(Py_IsFalse(flag));
}

op (_GUARD_IS_NONE_POP, (val -- )) {
DEOPT_IF(!Py_IsNone(val));
}

op (_GUARD_IS_NOT_NONE_POP, (val -- )) {
DEOPT_IF(Py_IsNone(val));
Py_DECREF(val);
}

op(_JUMP_TO_TOP, (--)) {
Expand Down
Loading

0 comments on commit a519b87

Please sign in to comment.