Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Include/internal/pycore_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_bitutils.h" // _Py_popcount32
#include "pycore_frame.h" // _PyInterpreterFrame

#ifdef __cplusplus
Expand Down
22 changes: 13 additions & 9 deletions Include/internal/pycore_opcode_metadata.h

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

12 changes: 12 additions & 0 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
"counter": 1,
"version": 2,
},
"POP_JUMP_IF_TRUE": {
"counter": 1,
},
"POP_JUMP_IF_FALSE": {
"counter": 1,
},
"POP_JUMP_IF_NONE": {
"counter": 1,
},
"POP_JUMP_IF_NOT_NONE": {
"counter": 1,
},
}

_inline_cache_entries = {
Expand Down
45 changes: 31 additions & 14 deletions Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,7 @@ def testfunc(x):
opt = _testinternalcapi.get_uop_optimizer()

with temporary_optimizer(opt):
testfunc(10)
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2470,7 +2470,7 @@ def testfunc(n):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(10)
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2485,7 +2485,7 @@ def testfunc(a):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(range(10))
testfunc(range(20))

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2495,12 +2495,13 @@ def testfunc(a):
def test_pop_jump_if_not_none(self):
def testfunc(a):
for x in a:
x = None
if x is not None:
x = 0

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(range(10))
testfunc(range(20))

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2515,7 +2516,7 @@ def testfunc(n):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(10)
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2530,7 +2531,7 @@ def testfunc(n):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(10)
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2550,7 +2551,7 @@ def testfunc(n):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(10)
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2568,8 +2569,8 @@ def testfunc(n):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
total = testfunc(10)
self.assertEqual(total, 45)
total = testfunc(20)
self.assertEqual(total, 190)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2589,9 +2590,9 @@ def testfunc(a):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
a = list(range(10))
a = list(range(20))
total = testfunc(a)
self.assertEqual(total, 45)
self.assertEqual(total, 190)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand All @@ -2611,9 +2612,9 @@ def testfunc(a):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
a = tuple(range(10))
a = tuple(range(20))
total = testfunc(a)
self.assertEqual(total, 45)
self.assertEqual(total, 190)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
Expand Down Expand Up @@ -2647,14 +2648,30 @@ def dummy(x):

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(10)
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
self.assertIn("_PUSH_FRAME", uops)
self.assertIn("_BINARY_OP_ADD_INT", uops)

def test_branch_taken(self):
def testfunc(n):
for i in range(n):
if i < 0:
i = 0
else:
i = 1

opt = _testinternalcapi.get_uop_optimizer()
with temporary_optimizer(opt):
testfunc(20)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
self.assertIn("_POP_JUMP_IF_TRUE", uops)


if __name__ == "__main__":
Expand Down
Loading