[pypy-commit] pypy jit-targets: renaming, redefining and reeanbling the "loop" counters (in progress)

hakanardo noreply at buildbot.pypy.org
Tue Nov 8 14:10:03 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-targets
Changeset: r48930:9b50e8266be0
Date: 2011-11-08 12:11 +0100
http://bitbucket.org/pypy/pypy/changeset/9b50e8266be0/

Log:	renaming, redefining and reeanbling the "loop" counters (in
	progress)

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
@@ -161,34 +161,35 @@
     def check_loops(self, expected=None, everywhere=False, **check):
         get_stats().check_loops(expected=expected, everywhere=everywhere,
                                 **check)        
-    def check_loop_count(self, count):
-        """NB. This is a hack; use check_tree_loop_count() or
-        check_enter_count() for the real thing.
-        This counts as 1 every bridge in addition to every loop; and it does
-        not count at all the entry bridges from interpreter, although they
-        are TreeLoops as well."""
-        return # FIXME
-        assert get_stats().compiled_count == count
-    def check_tree_loop_count(self, count):
-        return # FIXME
+    def check_trace_count(self, count):
+        # The number of traces compiled
         assert len(get_stats().loops) == count
-    def check_loop_count_at_most(self, count):
-        return # FIXME
-        assert get_stats().compiled_count <= count
+    def check_trace_count_at_most(self, count):
+        assert len(get_stats().loops) <= count
+
+    def check_jitcell_token_count(self, count):
+        tokens = set()
+        for loop in get_stats().loops:
+            for op in loop.operations:
+                descr = op.getdescr()
+                if isinstance(descr, history.TargetToken):
+                    descr = descr.targeting_jitcell_token
+                if isinstance(descr, history.JitCellToken):
+                    tokens.add(descr)
+        assert len(tokens) == count
+
     def check_enter_count(self, count):
-        return # FIXME
         assert get_stats().enter_count == count
     def check_enter_count_at_most(self, count):
-        return # FIXME
         assert get_stats().enter_count <= count
+
     def check_jumps(self, maxcount):
         return # FIXME
         assert get_stats().exec_jumps <= maxcount
+
     def check_aborted_count(self, count):
-        return # FIXME
         assert get_stats().aborted_count == count
     def check_aborted_count_at_least(self, count):
-        return # FIXME
         assert get_stats().aborted_count >= count
 
     def meta_interp(self, *args, **kwds):
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
@@ -78,7 +78,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 42
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2,
                            'guard_true': 2, 'int_sub': 2})
 
@@ -107,7 +107,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 1323
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         self.check_resops(int_mul=3)
 
     def test_loop_variant_mul_ovf(self):
@@ -124,7 +124,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 1323
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         self.check_resops(int_mul_ovf=3)
 
     def test_loop_invariant_mul1(self):
@@ -139,7 +139,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 252
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2,
                            'int_mul': 1, 'guard_true': 2, 'int_sub': 2})
 
@@ -157,7 +157,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 308
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         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,
@@ -177,7 +177,7 @@
             return res
         res = self.meta_interp(f, [6, 32])
         assert res == 3427
-        self.check_loop_count(3)
+        self.check_trace_count(3)
 
     def test_loop_invariant_mul_bridge_maintaining1(self):
         myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x'])
@@ -193,7 +193,7 @@
             return res
         res = self.meta_interp(f, [6, 32])
         assert res == 1167
-        self.check_loop_count(3)
+        self.check_trace_count(3)
         self.check_resops({'int_lt': 3, 'int_gt': 2, 'int_add': 5,
                            'guard_true': 3, 'int_sub': 4, 'jump': 2,
                            'int_mul': 2, 'guard_false': 2})
@@ -213,7 +213,7 @@
             return res
         res = self.meta_interp(f, [6, 32])
         assert res == 1692
-        self.check_loop_count(3)
+        self.check_trace_count(3)
         self.check_resops({'int_lt': 3, 'int_gt': 2, 'int_add': 5,
                            'guard_true': 3, 'int_sub': 4, 'jump': 2,
                            'int_mul': 2, 'guard_false': 2})
@@ -233,7 +233,7 @@
             return res
         res = self.meta_interp(f, [6, 32, 16])
         assert res == 1692
-        self.check_loop_count(3)
+        self.check_trace_count(3)
         self.check_resops({'int_lt': 2, 'int_gt': 4, 'guard_false': 2,
                            'guard_true': 4, 'int_sub': 4, 'jump': 3,
                            'int_mul': 3, 'int_add': 4})
@@ -256,7 +256,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 252
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2,
                            'getfield_gc_pure': 1, 'int_mul': 1,
                            'guard_true': 2, 'int_sub': 2})
@@ -559,11 +559,11 @@
         #
         res = self.meta_interp(f, [10, 84])
         assert res == -6
-        self.check_loop_count(0)
+        self.check_trace_count(0)
         #
         res = self.meta_interp(f, [3, 19])
         assert res == -2
-        self.check_loop_count(1)
+        self.check_trace_count(1)
 
     def test_can_never_inline(self):
         def can_never_inline(x):
@@ -858,7 +858,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 42.0
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         self.check_resops({'jump': 1, 'float_gt': 2, 'float_add': 2,
                            'float_sub': 2, 'guard_true': 2})
 
@@ -874,7 +874,7 @@
         res = self.meta_interp(f, [7])
         assert res == 0
 
-    def test_bridge_from_interpreter(self):
+    def test_bridge_from_interpreter_1(self):
         mydriver = JitDriver(reds = ['n'], greens = [])
 
         def f(n):
@@ -884,7 +884,7 @@
                 n -= 1
 
         self.meta_interp(f, [20], repeat=7)
-        self.check_tree_loop_count(2)      # the loop and the entry path
+        self.check_jitcell_token_count(2)      # the loop and the entry path
         # we get:
         #    ENTER             - compile the new loop and the entry bridge
         #    ENTER             - compile the leaving path
@@ -1255,11 +1255,11 @@
 
         res = self.meta_interp(f, [10, 3])
         assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0
-        self.check_tree_loop_count(2)
+        self.check_jitcell_token_count(2)
 
         res = self.meta_interp(f, [10, 13])
         assert res == 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0
-        self.check_tree_loop_count(0)
+        self.check_jitcell_token_count(0)
 
     def test_dont_look_inside(self):
         @dont_look_inside
@@ -1340,7 +1340,7 @@
             return res
         res = self.meta_interp(f, [6, 7])
         assert res == 42
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         self.check_resops(call=2)
 
     def test_merge_guardclass_guardvalue(self):
@@ -1635,7 +1635,7 @@
                 promote(a)
                 x -= 1
         self.meta_interp(f, [50])
-        self.check_loop_count(1)
+        self.check_trace_count(1)
         # this checks that the logic triggered by make_a_counter_per_value()
         # works and prevents generating tons of bridges
 
@@ -1730,7 +1730,7 @@
             return a1.val + b1.val
         res = self.meta_interp(g, [6, 7])
         assert res == 6*8 + 6**8
-        self.check_loop_count(5)
+        self.check_trace_count(5)
         self.check_resops({'guard_class': 2, 'int_gt': 4,
                            'getfield_gc': 4, 'guard_true': 4,
                            'int_sub': 4, 'jump': 2, 'int_mul': 2,
@@ -1774,7 +1774,7 @@
             return a1.val + b1.val
         res = self.meta_interp(g, [6, 20])
         assert res == g(6, 20)
-        self.check_loop_count(9)
+        self.check_trace_count(9)
         self.check_resops(getarrayitem_gc=10)
 
     def test_multiple_specialied_versions_bridge(self):
@@ -1962,7 +1962,7 @@
             return a1.val + b1.val
         res = self.meta_interp(g, [3, 23])
         assert res == 7068153
-        self.check_loop_count(7)
+        self.check_trace_count(7)
         self.check_resops(guard_true=6, guard_class=2, int_mul=3,
                           int_add=3, guard_false=3)
 
@@ -2048,7 +2048,7 @@
             return n
         res = self.meta_interp(f, [sys.maxint-10])
         assert res == 11
-        self.check_tree_loop_count(2)
+        self.check_jitcell_token_count(2)
 
     def test_wrap_around_mul(self):
         myjitdriver = JitDriver(greens = [], reds = ['x', 'n'])
@@ -2064,7 +2064,7 @@
             return n
         res = self.meta_interp(f, [sys.maxint>>10])
         assert res == 11
-        self.check_tree_loop_count(2)
+        self.check_jitcell_token_count(2)
 
     def test_wrap_around_sub(self):
         myjitdriver = JitDriver(greens = [], reds = ['x', 'n'])
@@ -2080,7 +2080,7 @@
             return n
         res = self.meta_interp(f, [10-sys.maxint])
         assert res == 12
-        self.check_tree_loop_count(2)
+        self.check_jitcell_token_count(2)
 
     def test_caching_setfield(self):
         myjitdriver = JitDriver(greens = [], reds = ['sa', 'i', 'n', 'a', 'node'])
@@ -2600,9 +2600,9 @@
                 i += 1
             return sa
         assert self.meta_interp(f, [20, 2]) == f(20, 2)
-        self.check_tree_loop_count(4)
+        self.check_jitcell_token_count(4)
         assert self.meta_interp(f, [20, 3]) == f(20, 3)
-        self.check_tree_loop_count(5)
+        self.check_jitcell_token_count(5)
 
     def test_max_retrace_guards(self):
         myjitdriver = JitDriver(greens = [], reds = ['n', 'i', 'sa', 'a'])
@@ -2619,9 +2619,9 @@
                 i += 1
             return sa
         assert self.meta_interp(f, [20, 1]) == f(20, 1)
-        self.check_tree_loop_count(2)
+        self.check_jitcell_token_count(2)
         assert self.meta_interp(f, [20, 10]) == f(20, 10)
-        self.check_tree_loop_count(5)
+        self.check_jitcell_token_count(5)
 
 
     def test_retrace_limit_with_extra_guards(self):
@@ -2642,9 +2642,9 @@
                 i += 1
             return sa
         assert self.meta_interp(f, [20, 2]) == f(20, 2)
-        self.check_tree_loop_count(4)
+        self.check_jitcell_token_count(4)
         assert self.meta_interp(f, [20, 3]) == f(20, 3)
-        self.check_tree_loop_count(5)
+        self.check_jitcell_token_count(5)
 
     def test_retrace_ending_up_retrazing_another_loop(self):
 
@@ -2692,7 +2692,7 @@
         # Thus we end up with:
         #   1 preamble and 1 specialized version of first loop
         #   1 preamble and 2 specialized version of second loop
-        self.check_tree_loop_count(2 + 3)
+        self.check_jitcell_token_count(2 + 3)
 
         # FIXME: Add a gloabl retrace counter and test that we are not trying more than 5 times.
 
@@ -2743,14 +2743,14 @@
 
         res = self.meta_interp(f, [10, 7])
         assert res == f(10, 7)
-        self.check_tree_loop_count(4)
+        self.check_jitcell_token_count(4)
 
         def g(n):
             return f(n, 2) + f(n, 3)
 
         res = self.meta_interp(g, [10])
         assert res == g(10)
-        self.check_tree_loop_count(6)
+        self.check_jitcell_token_count(6)
 
 
         def g(n):
@@ -2758,7 +2758,7 @@
 
         res = self.meta_interp(g, [10])
         assert res == g(10)
-        self.check_tree_loop_count(8)
+        self.check_jitcell_token_count(8)
 
     def test_frame_finished_during_retrace(self):
         class Base(object):
@@ -2887,7 +2887,7 @@
         # Thus we end up with:
         #   1 preamble and 1 specialized version of first loop
         #   1 preamble and 2 specialized version of second loop
-        self.check_tree_loop_count(2 + 3)
+        self.check_jitcell_token_count(2 + 3)
 
         # FIXME: Add a gloabl retrace counter and test that we are not trying more than 5 times.
 
@@ -2899,7 +2899,7 @@
         res = self.meta_interp(g, [10])
         assert res == g(10)
         # 1 preamble and 6 speciealized versions of each loop
-        self.check_tree_loop_count(2*(1 + 6))
+        self.check_jitcell_token_count(2*(1 + 6))
 
     def test_continue_tracing_with_boxes_in_start_snapshot_replaced_by_optimizer(self):
         myjitdriver = JitDriver(greens = [], reds = ['sa', 'n', 'a', 'b'])
@@ -3148,7 +3148,7 @@
             return sa
         res = self.meta_interp(f, [32])
         assert res == f(32)
-        self.check_tree_loop_count(3)
+        self.check_jitcell_token_count(3)
 
     def test_two_loopinvariant_arrays2(self):
         from pypy.rpython.lltypesystem import lltype, llmemory, rffi
@@ -3171,7 +3171,7 @@
             return sa
         res = self.meta_interp(f, [32])
         assert res == f(32)
-        self.check_tree_loop_count(3)
+        self.check_jitcell_token_count(3)
 
     def test_two_loopinvariant_arrays3(self):
         from pypy.rpython.lltypesystem import lltype, llmemory, rffi
@@ -3195,7 +3195,7 @@
             return sa
         res = self.meta_interp(f, [32])
         assert res == f(32)
-        self.check_tree_loop_count(2)
+        self.check_jitcell_token_count(2)
 
     def test_two_loopinvariant_arrays_boxed(self):
         class A(object):


More information about the pypy-commit mailing list