[pypy-svn] r76134 - in pypy/branch/kill-caninline/pypy/jit: codewriter codewriter/test metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Mon Jul 12 13:24:24 CEST 2010


Author: arigo
Date: Mon Jul 12 13:24:17 2010
New Revision: 76134

Modified:
   pypy/branch/kill-caninline/pypy/jit/codewriter/jtransform.py
   pypy/branch/kill-caninline/pypy/jit/codewriter/test/test_flatten.py
   pypy/branch/kill-caninline/pypy/jit/metainterp/blackhole.py
   pypy/branch/kill-caninline/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/kill-caninline/pypy/jit/metainterp/test/test_jitdriver.py
   pypy/branch/kill-caninline/pypy/jit/metainterp/warmspot.py
Log:
Rename: a 'can_enter_jit' in the source graph becomes a 'loop_header' operation
in the transformed graph, as its only purpose in the transformed graph is to
detect loops.  The goal is later to add a jitdriver.loop_header() that has only
the latter effect.



Modified: pypy/branch/kill-caninline/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/kill-caninline/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/kill-caninline/pypy/jit/codewriter/jtransform.py	Mon Jul 12 13:24:17 2010
@@ -809,10 +809,13 @@
         return ops + [op1, op2]
 
     def handle_jit_marker__can_enter_jit(self, op, jitdriver):
+        # a 'can_enter_jit' in the source graph becomes a 'loop_header'
+        # operation in the transformed graph, as its only purpose in
+        # the transformed graph is to detect loops.
         jd = self.callcontrol.jitdriver_sd_from_jitdriver(jitdriver)
         assert jd is not None
         c_index = Constant(jd.index, lltype.Signed)
-        return SpaceOperation('can_enter_jit', [c_index], None)
+        return SpaceOperation('loop_header', [c_index], None)
 
     def rewrite_op_debug_assert(self, op):
         log.WARNING("found debug_assert in %r; should have be removed" %

Modified: pypy/branch/kill-caninline/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/kill-caninline/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/branch/kill-caninline/pypy/jit/codewriter/test/test_flatten.py	Mon Jul 12 13:24:17 2010
@@ -593,7 +593,8 @@
             -live- %i0, %i1
             int_guard_value %i0
             jit_merge_point $27, I[%i0], R[], F[], I[%i1], R[], F[]
-            can_enter_jit $27
+            -live-
+            loop_header $27
             void_return
         """, transform=True, liveness=True, cc=MyFakeCallControl(), jd=jd)
 

Modified: pypy/branch/kill-caninline/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/kill-caninline/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/kill-caninline/pypy/jit/metainterp/blackhole.py	Mon Jul 12 13:24:17 2010
@@ -764,7 +764,7 @@
     # the main hints and recursive calls
 
     @arguments("i")
-    def bhimpl_can_enter_jit(jdindex):
+    def bhimpl_loop_header(jdindex):
         pass
 
     @arguments("self", "i", "I", "R", "F", "I", "R", "F")

Modified: pypy/branch/kill-caninline/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/kill-caninline/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/kill-caninline/pypy/jit/metainterp/pyjitpl.py	Mon Jul 12 13:24:17 2010
@@ -795,8 +795,8 @@
         return clsbox
 
     @arguments("int")
-    def opimpl_can_enter_jit(self, jdindex):
-        self.metainterp.seen_can_enter_jit_for_jdindex = jdindex
+    def opimpl_loop_header(self, jdindex):
+        self.metainterp.seen_loop_header_for_jdindex = jdindex
 
     def verify_green_args(self, jitdriver_sd, varargs):
         num_green_args = jitdriver_sd.num_green_args
@@ -810,23 +810,23 @@
         self.verify_green_args(jitdriver_sd, greenboxes)
         # xxx we may disable the following line in some context later
         self.debug_merge_point(jitdriver_sd, greenboxes)
-        if self.metainterp.seen_can_enter_jit_for_jdindex < 0:
+        if self.metainterp.seen_loop_header_for_jdindex < 0:
             return
         #
-        assert self.metainterp.seen_can_enter_jit_for_jdindex == jdindex, (
-            "found a can_enter_jit for a JitDriver that does not match "
+        assert self.metainterp.seen_loop_header_for_jdindex == jdindex, (
+            "found a loop_header for a JitDriver that does not match "
             "the following jit_merge_point's")
-        self.metainterp.seen_can_enter_jit_for_jdindex = -1
+        self.metainterp.seen_loop_header_for_jdindex = -1
         #
         if not self.metainterp.in_recursion:
             assert jitdriver_sd is self.metainterp.jitdriver_sd
             # Set self.pc to point to jit_merge_point instead of just after:
-            # if reached_can_enter_jit() raises SwitchToBlackhole, then the
+            # if reached_loop_header() raises SwitchToBlackhole, then the
             # pc is still at the jit_merge_point, which is a point that is
             # much less expensive to blackhole out of.
             saved_pc = self.pc
             self.pc = orgpc
-            self.metainterp.reached_can_enter_jit(greenboxes, redboxes)
+            self.metainterp.reached_loop_header(greenboxes, redboxes)
             self.pc = saved_pc
         else:
             warmrunnerstate = jitdriver_sd.warmstate
@@ -1584,7 +1584,7 @@
         redkey = original_boxes[num_green_args:]
         self.resumekey = compile.ResumeFromInterpDescr(original_greenkey,
                                                        redkey)
-        self.seen_can_enter_jit_for_jdindex = -1
+        self.seen_loop_header_for_jdindex = -1
         try:
             self.interpret()
         except GenerateMergePoint, gmp:
@@ -1611,7 +1611,7 @@
         # because we cannot reconstruct the beginning of the proper loop
         self.current_merge_points = [(original_greenkey, -1)]
         self.resumekey = key
-        self.seen_can_enter_jit_for_jdindex = -1
+        self.seen_loop_header_for_jdindex = -1
         try:
             self.prepare_resume_from_failure(key.guard_opnum)
             self.interpret()
@@ -1641,7 +1641,7 @@
             else:
                 duplicates[box] = None
 
-    def reached_can_enter_jit(self, greenboxes, redboxes):
+    def reached_loop_header(self, greenboxes, redboxes):
         duplicates = {}
         self.remove_consts_and_duplicates(redboxes, len(redboxes),
                                           duplicates)
@@ -1655,7 +1655,7 @@
             live_arg_boxes += self.virtualizable_boxes
             live_arg_boxes.pop()
         assert len(self.virtualref_boxes) == 0, "missing virtual_ref_finish()?"
-        # Called whenever we reach the 'can_enter_jit' hint.
+        # Called whenever we reach the 'loop_header' hint.
         # First, attempt to make a bridge:
         # - if self.resumekey is a ResumeGuardDescr, it starts from a guard
         #   that failed;

Modified: pypy/branch/kill-caninline/pypy/jit/metainterp/test/test_jitdriver.py
==============================================================================
--- pypy/branch/kill-caninline/pypy/jit/metainterp/test/test_jitdriver.py	(original)
+++ pypy/branch/kill-caninline/pypy/jit/metainterp/test/test_jitdriver.py	Mon Jul 12 13:24:17 2010
@@ -29,11 +29,14 @@
             while r > 0:
                 myjitdriver2.can_enter_jit(g=g, r=r)
                 myjitdriver2.jit_merge_point(g=g, r=r)
-                r += loop1(r, g) - 1
+                r += loop1(r, g) + (-1)
             return r
         #
         res = self.meta_interp(loop2, [4, 40], repeat=7, inline=True)
         assert res == loop2(4, 40)
+        # we expect only one int_sub, corresponding to the single
+        # compiled instance of loop1()
+        self.check_loops(int_sub=1)
         # the following numbers are not really expectations of the test
         # itself, but just the numbers that we got after looking carefully
         # at the generated machine code
@@ -41,7 +44,7 @@
         self.check_tree_loop_count(4)    # 2 x loop, 2 x enter bridge
         self.check_enter_count(7)
 
-    def test_simple_inline(self):
+    def test_inline(self):
         # this is not an example of reasonable code: loop1() is unrolled
         # 'n/m' times, where n and m are given as red arguments.
         myjitdriver1 = JitDriver(greens=[], reds=['n', 'm'],

Modified: pypy/branch/kill-caninline/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/kill-caninline/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/kill-caninline/pypy/jit/metainterp/warmspot.py	Mon Jul 12 13:24:17 2010
@@ -473,7 +473,12 @@
             jitdriver = op.args[1].value
             assert jitdriver in sublists, \
                    "can_enter_jit with no matching jit_merge_point"
-            sublists[jitdriver].append((graph, block, index))
+            origportalgraph = jd._jit_merge_point_pos[0]
+            if graph is not origportalgraph:
+                sublists[jitdriver].append((graph, block, index))
+            else:
+                pass   # a 'can_enter_jit' before the 'jit-merge_point', but
+                       # originally in the same function: we ignore it here
         for jd in self.jitdrivers_sd:
             sublist = sublists[jd.jitdriver]
             assert len(sublist) > 0, \
@@ -682,17 +687,6 @@
         origblock.exitswitch = None
         origblock.recloseblock(Link([v_result], origportalgraph.returnblock))
         #
-        # Also kill any can_enter_jit left behind (example: see
-        # test_jitdriver.test_simple, which has a can_enter_jit in
-        # loop1's origportalgraph)
-        can_enter_jits = _find_jit_marker([origportalgraph], 'can_enter_jit')
-        for _, block, i in can_enter_jits:
-            op = block.operations[i]
-            assert op.opname == 'jit_marker'
-            block.operations[i] = SpaceOperation('same_as',
-                                                 [Constant(None, lltype.Void)],
-                                                 op.result)
-        #
         checkgraph(origportalgraph)
 
     def add_finish(self):



More information about the Pypy-commit mailing list