[pypy-svn] pypy default: make sure that we can use ID: also for loop conditions

antocuni commits-noreply at bitbucket.org
Thu Mar 10 20:43:16 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r42496:c8bc558fe8d7
Date: 2011-03-10 17:50 +0100
http://bitbucket.org/pypy/pypy/changeset/c8bc558fe8d7/

Log:	make sure that we can use ID: also for loop conditions

diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py
--- a/pypy/module/pypyjit/test_pypy_c/model.py
+++ b/pypy/module/pypyjit/test_pypy_c/model.py
@@ -99,12 +99,11 @@
         # 1. compute the ids of self, i.e. the outer function
         id2opcodes = find_ids(self.code)
         all_my_opcodes = self.get_set_of_opcodes()
-        # XXX: for now, we just look for the first opcode in the id range
         for id, opcodes in id2opcodes.iteritems():
             if not opcodes:
                 continue
-            target_opcode = opcodes[0]
-            if target_opcode in all_my_opcodes:
+            target_opcodes = set(opcodes)
+            if all_my_opcodes.intersection(target_opcodes):
                 ids[id] = opcodes
         #
         # 2. compute the ids of all the inlined functions

diff --git a/pypy/module/pypyjit/test_pypy_c/test_model.py b/pypy/module/pypyjit/test_pypy_c/test_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_model.py
@@ -86,6 +86,7 @@
         opcodes_names = [opcode.__class__.__name__ for opcode in myline]
         assert opcodes_names == ['LOAD_FAST', 'LOAD_CONST', 'BINARY_ADD', 'STORE_FAST']
 
+
 class TestOpMatcher(object):
 
     def match(self, src1, src2):
@@ -283,7 +284,7 @@
     def test_ops_by_id(self):
         def f():
             i = 0
-            while i < 1003:
+            while i < 1003: # ID: cond
                 i += 1 # ID: increment
                 a = 0  # to make sure that JUMP_ABSOLUTE is not part of the ID
             return i
@@ -293,6 +294,12 @@
         #
         ops = loop.ops_by_id('increment')
         assert log.opnames(ops) == ['int_add']
+        #
+        ops = loop.ops_by_id('cond')
+        # the 'jump' at the end is because the last opcode in the loop
+        # coincides with the first, and so it thinks that 'jump' belongs to
+        # the id
+        assert log.opnames(ops) == ['int_lt', 'guard_true', 'jump']
 
     def test_ops_by_id_and_opcode(self):
         def f():


More information about the Pypy-commit mailing list