Author: Hakan Ardo <[email protected]>
Branch: jit-targets
Changeset: r49861:7b57bed3d875
Date: 2011-11-27 19:49 +0100
http://bitbucket.org/pypy/pypy/changeset/7b57bed3d875/

Log:    A check function that allows counting the ops in the peeled loop
        only. It only works in the simplest case when there is exactly one
        jump (ie no bridges not ending in finnish)

diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -1052,6 +1052,9 @@
         insns = {}
         for loop in self.get_all_loops():
             insns = loop.summary(adding_insns=insns)
+        return self._check_insns(insns, expected, check)
+
+    def _check_insns(self, insns, expected, check):
         if expected is not None:
             insns.pop('debug_merge_point', None)
             insns.pop('label', None)
@@ -1062,6 +1065,30 @@
             assert found == expected_count, (
                 "found %d %r, expected %d" % (found, insn, expected_count))
         return insns
+
+    def check_simple_loop(self, expected=None, **check):
+        # Usefull in the simplest case when we have only one trace ending with
+        # a jump back to itself and possibly a few bridges ending with finnish.
+        # Only the operations within the loop formed by that single jump will
+        # be counted.
+        loops = self.get_all_loops()
+        assert len(loops) == 1
+        loop = loops[0]
+        jumpop = loop.operations[-1]
+        assert jumpop.getopnum() == rop.JUMP
+        assert self.check_resops(jump=1)
+        labels = [op for op in loop.operations if op.getopnum() == rop.LABEL]
+        targets = [op._descr_wref() for op in labels]
+        assert None not in targets # TargetToken was freed, give up
+        target = jumpop._descr_wref()
+        assert target
+        assert targets.count(target) == 1
+        i = loop.operations.index(labels[targets.index(target)])
+        insns = {}
+        for op in loop.operations[i:]:
+            opname = op.getopname()
+            insns[opname] = insns.get(opname, 0) + 1
+        return self._check_insns(insns, expected, check)
         
     def check_loops(self, expected=None, everywhere=False, **check):
         insns = {}
diff --git a/pypy/jit/metainterp/test/support.py 
b/pypy/jit/metainterp/test/support.py
--- a/pypy/jit/metainterp/test/support.py
+++ b/pypy/jit/metainterp/test/support.py
@@ -156,6 +156,8 @@
     basic = True
     def check_resops(self, expected=None, **check):
         get_stats().check_resops(expected=expected, **check)
+    def check_simple_loop(self, expected=None, **check):
+        get_stats().check_simple_loop(expected=expected, **check)
 
     
 
diff --git a/pypy/jit/metainterp/test/test_ajit.py 
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -108,7 +108,7 @@
         res = self.meta_interp(f, [6, 7])
         assert res == 1323
         self.check_trace_count(1)
-        self.check_resops(int_mul=3)
+        self.check_simple_loop(int_mul=1)
 
     def test_loop_variant_mul_ovf(self):
         myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x'])
@@ -125,7 +125,7 @@
         res = self.meta_interp(f, [6, 7])
         assert res == 1323
         self.check_trace_count(1)
-        self.check_resops(int_mul_ovf=3)
+        self.check_simple_loop(int_mul_ovf=1)
 
     def test_loop_invariant_mul1(self):
         myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x'])
@@ -140,6 +140,7 @@
         res = self.meta_interp(f, [6, 7])
         assert res == 252
         self.check_trace_count(1)
+        self.check_simple_loop(int_mul=0)
         self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2,
                            'int_mul': 1, 'guard_true': 2, 'int_sub': 2})
 
@@ -158,6 +159,7 @@
         res = self.meta_interp(f, [6, 7])
         assert res == 308
         self.check_trace_count(1)
+        self.check_simple_loop(int_mul_ovf=0)
         self.check_resops({'jump': 1, 'int_lshift': 2, 'int_gt': 2,
                            'int_mul_ovf': 1, 'int_add': 4,
                            'guard_true': 2, 'guard_no_overflow': 1,
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to