[pypy-svn] r31917 - in pypy/dist/pypy/jit/timeshifter: . test

arigo at codespeak.net arigo at codespeak.net
Fri Sep 1 13:20:57 CEST 2006


Author: arigo
Date: Fri Sep  1 13:20:56 2006
New Revision: 31917

Modified:
   pypy/dist/pypy/jit/timeshifter/rtimeshift.py
   pypy/dist/pypy/jit/timeshifter/rvalue.py
   pypy/dist/pypy/jit/timeshifter/test/test_tlr.py
Log:
(pedronis, arigo)

Bug, test and fix.  The diff looks short but don't underestimate the
time it took to get it.

In case of generalization, instead of trying to build the next
generalized block "by hand", we now only generalize the redboxes state
and reuse the existing logic to start a new block from this state.



Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py	Fri Sep  1 13:20:56 2006
@@ -137,27 +137,31 @@
 def enter_graph(builder, backstate=None):
     return builder.build_jitstate(backstate)
 
-def retrieve_jitstate_for_merge(states_dic, jitstate, key, redboxes):
+def start_new_block(states_dic, jitstate, key, redboxes):
     rgenop = jitstate.rgenop
+    memo = rvalue.freeze_memo()
+    frozens = [redbox.freeze(memo) for redbox in redboxes]
+    memo = rvalue.exactmatch_memo()
+    outgoingvarboxes = []
+    for i in range(len(redboxes)):
+        res = frozens[i].exactmatch(redboxes[i], outgoingvarboxes, memo)
+        assert res, "exactmatch() failed"
+    newblock = rgenop.newblock()
+    linkargs = []
+    for box in outgoingvarboxes:
+        linkargs.append(box.getgenvar(None))
+        box.genvar = newblock.geninputarg(box.kind)
+    jitstate.curbuilder.enter_block(linkargs, newblock)
+    states_dic[key] = frozens, newblock
+    return jitstate
+start_new_block._annspecialcase_ = "specialize:arglltype(2)"
+
+def retrieve_jitstate_for_merge(states_dic, jitstate, key, redboxes):
     mylocalredboxes = redboxes
     redboxes = list(redboxes)
     jitstate.extend_with_parent_locals(redboxes)
     if key not in states_dic:
-        memo = rvalue.freeze_memo()
-        frozens = [redbox.freeze(memo) for redbox in redboxes]
-        memo = rvalue.exactmatch_memo()
-        outgoingvarboxes = []
-        for i in range(len(redboxes)):
-            res = frozens[i].exactmatch(redboxes[i], outgoingvarboxes, memo)
-            assert res, "exactmatch() failed"
-        newblock = rgenop.newblock()
-        linkargs = []
-        for box in outgoingvarboxes:
-            linkargs.append(box.getgenvar(None))
-            box.genvar = newblock.geninputarg(box.kind)
-        jitstate.curbuilder.enter_block(linkargs, newblock)
-        states_dic[key] = frozens, newblock
-        return jitstate
+        return start_new_block(states_dic, jitstate, key, redboxes)
 
     frozens, oldblock = states_dic[key]
     memo = rvalue.exactmatch_memo()
@@ -176,28 +180,20 @@
         jitstate.curbuilder.leave_block()
         jitstate.curbuilder.finish_and_goto(linkargs, oldblock)
         return None
-    
-    # Make a more general block
+
+    # We need a more general block.  Do it by generalizing all the
+    # redboxes from outgoingvarboxes, by making them variables.
+    # Then we make a new block based on this new state.
     jitstate = dyn_enter_block(jitstate, outgoingvarboxes)
-    newblock = rgenop.newblock()
-    linkargs = []
     replace_memo = rvalue.copy_memo()
     for box in outgoingvarboxes:
-        linkargs.append(box.getgenvar(jitstate.curbuilder))
-    for box in outgoingvarboxes:
-        if box.is_constant():            # constant boxes considered immutable:
-            box = box.copy(replace_memo) # copy to avoid patching the original
-        box.genvar = newblock.geninputarg(box.kind)
+        box = box.forcevar(jitstate.curbuilder, replace_memo)
     if replace_memo.boxes:
         for i in range(len(mylocalredboxes)):
             newbox = redboxes[i].replace(replace_memo)
             mylocalredboxes[i] = redboxes[i] = newbox
     jitstate.curbuilder.leave_block()
-    jitstate.curbuilder.enter_block(linkargs, newblock)
-    memo = rvalue.freeze_memo()
-    frozens = [redbox.freeze(memo) for redbox in redboxes]
-    states_dic[key] = frozens, newblock
-    return jitstate
+    return start_new_block(states_dic, jitstate, key, redboxes)
 retrieve_jitstate_for_merge._annspecialcase_ = "specialize:arglltype(2)"
     
 def enter_block(jitstate, redboxes):

Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvalue.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rvalue.py	Fri Sep  1 13:20:56 2006
@@ -45,6 +45,17 @@
             memo[self] = None
             self.genvar = newblock.geninputarg(self.kind)
 
+    def forcevar(self, builder, memo):
+        if self.is_constant():
+            # cannot mutate constant boxes in-place
+            box = self.copy(memo)
+            box.genvar = builder.genop("same_as", [self.genvar], self.kind)
+            return box
+        else:
+            # force virtual containers
+            self.getgenvar(builder)
+            return self
+
     def replace(self, memo):
         memo = memo.boxes
         return memo.setdefault(self, self)

Modified: pypy/dist/pypy/jit/timeshifter/test/test_tlr.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_tlr.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_tlr.py	Fri Sep  1 13:20:56 2006
@@ -22,7 +22,6 @@
                              policy=P_OOPSPEC)
         assert res == 3111696
 
-        import py; py.test.skip("XXX the following fails")
         res = self.timeshift(tlr_interpret, [bytecode, 9], [0, 1],
                              policy=P_OOPSPEC)
         assert res == 81



More information about the Pypy-commit mailing list