[pypy-svn] pypy default: add a way to get the ops for just the specified opcode

antocuni commits-noreply at bitbucket.org
Wed Feb 23 18:59:11 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r42241:6466e4ce87f0
Date: 2011-02-23 18:58 +0100
http://bitbucket.org/pypy/pypy/changeset/6466e4ce87f0/

Log:	add a way to get the ops for just the specified opcode

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
@@ -130,11 +130,13 @@
             for op in self._ops_for_chunk(chunk, include_debug_merge_points):
                 yield op
 
-    def ops_by_id(self, id, include_debug_merge_points=False):
+    def ops_by_id(self, id, include_debug_merge_points=False, opcode=None):
+        opcode_name = opcode
         target_opcodes = self.ids[id]
         for chunk in self.flatten_chunks():
             opcode = chunk.getopcode()
-            if opcode in target_opcodes:
+            if opcode in target_opcodes and (opcode_name is None or
+                                             opcode.__class__.__name__ == opcode_name):
                 for op in self._ops_for_chunk(chunk, include_debug_merge_points):
                     yield op
 

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
@@ -142,6 +142,26 @@
         opnames = [op.name for op in ops]
         assert opnames == ['int_add']
 
+    def test_ops_by_id_and_opcode(self):
+        def f():
+            i = 0
+            j = 0
+            while i < 1003:
+                i += 1; j -= 1 # ID: foo
+                a = 0  # to make sure that JUMP_ABSOLUTE is not part of the ID
+            return i
+        #
+        log = self.run(f)
+        loop, = log.loops_by_id('foo')
+        #
+        ops = list(loop.ops_by_id('foo', opcode='INPLACE_ADD'))
+        opnames = [op.name for op in ops]
+        assert opnames == ['int_add']
+        #
+        ops = list(loop.ops_by_id('foo', opcode='INPLACE_SUBTRACT'))
+        opnames = [op.name for op in ops]
+        assert opnames == ['int_sub_ovf', 'guard_no_overflow']
+        
 
     def test_inlined_function(self):
         def f():


More information about the Pypy-commit mailing list