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

pedronis at codespeak.net pedronis at codespeak.net
Sat Nov 25 18:27:56 CET 2006


Author: pedronis
Date: Sat Nov 25 18:27:54 2006
New Revision: 34969

Modified:
   pypy/dist/pypy/jit/timeshifter/hrtyper.py
   pypy/dist/pypy/jit/timeshifter/rcontainer.py
   pypy/dist/pypy/jit/timeshifter/rtimeshift.py
   pypy/dist/pypy/jit/timeshifter/rvalue.py
   pypy/dist/pypy/jit/timeshifter/test/test_portal.py
   pypy/dist/pypy/jit/timeshifter/test/test_promotion.py
Log:
(arre, arigo around, pedronis)

now that we can return multiple states from a function, try to avoid forcing virtual structs at merge points.

Still force merges when returning from the portal.

Now test_virt_obj_method_call_promote passes, als test_factorial for the tlc only promotes once and produces
a box at the end for the result, which is good.



Modified: pypy/dist/pypy/jit/timeshifter/hrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/hrtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/hrtyper.py	Sat Nov 25 18:27:54 2006
@@ -155,14 +155,20 @@
         entrygraph = self.annotator.translator.graphs[0]
         if origportalgraph:
             portalgraph = bk.get_graph_by_key(origportalgraph, None)
+            leaveportalgraph = portalgraph
         else:
             portalgraph = None
+            # in the case of tests not specifying a portal
+            # we still need to force merges when entry
+            # returns
+            leaveportalgraph = entrygraph
+            
         pending = [entrygraph]
         seen = {entrygraph: True}
         while pending:
             graph = pending.pop()
             for nextgraph in self.transform_graph(graph,
-                                is_portal=graph is portalgraph):
+                                is_portal=graph is leaveportalgraph):
                 if nextgraph not in seen:
                     pending.append(nextgraph)
                     seen[nextgraph] = True

Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py	Sat Nov 25 18:27:54 2006
@@ -1,3 +1,4 @@
+
 import operator
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.annlowlevel import cachedtype
@@ -192,6 +193,8 @@
             outgoingvarboxes.append(vstruct.ownbox)
             return False
         if self.typedesc is not vstruct.typedesc:
+            if not memo.force_merge:
+                raise rvalue.DontMerge
             outgoingvarboxes.append(vstruct.ownbox)
             return False
         contmemo[self] = vstruct

Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py	Sat Nov 25 18:27:54 2006
@@ -237,9 +237,6 @@
         #debug_print(lltype.Void, "PROMOTION ROOT")
 start_new_block._annspecialcase_ = "specialize:arglltype(2)"
 
-class DontMerge(Exception):
-    pass
-
 def retrieve_jitstate_for_merge(states_dic, jitstate, key, global_resumer,
                                 force_merge=False):
     if key not in states_dic:
@@ -255,7 +252,7 @@
         
         try:
             match = frozen.exactmatch(jitstate, outgoingvarboxes, memo)
-        except DontMerge:
+        except rvalue.DontMerge:
             continue
         if match:
             linkargs = []

Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvalue.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rvalue.py	Sat Nov 25 18:27:54 2006
@@ -25,6 +25,8 @@
 def unfreeze_memo():
     return Memo()
 
+class DontMerge(Exception):
+    pass
 
 class RedBox(object):
     __slots__ = ['kind', 'genvar']
@@ -397,7 +399,12 @@
     def exactmatch(self, box, outgoingvarboxes, memo):
         assert isinstance(box, PtrRedBox)
         memo.partialdatamatch[box] = None     # could do better
-        return FrozenConst.exactmatch(self, box, outgoingvarboxes, memo)
+        match = FrozenConst.exactmatch(self, box, outgoingvarboxes, memo)
+        if not memo.force_merge and not match:
+            from pypy.jit.timeshifter.rcontainer import VirtualContainer
+            if isinstance(box.content, VirtualContainer):
+                raise DontMerge
+        return match
 
     def unfreeze(self, incomingvarboxes, memo):
         return PtrRedBox(self.kind, self.gv_const)
@@ -408,7 +415,12 @@
     def exactmatch(self, box, outgoingvarboxes, memo):
         assert isinstance(box, PtrRedBox)
         memo.partialdatamatch[box] = None
-        return FrozenVar.exactmatch(self, box, outgoingvarboxes, memo)
+        match = FrozenVar.exactmatch(self, box, outgoingvarboxes, memo)
+        if not memo.force_merge and not match:
+            from pypy.jit.timeshifter.rcontainer import VirtualContainer
+            if isinstance(box.content, VirtualContainer):
+                raise DontMerge
+        return match
 
     def unfreeze(self, incomingvarboxes, memo):
         memo = memo.boxes
@@ -431,7 +443,12 @@
                                                         memo.partialdatamatch)
         # skip the parent's exactmatch()!
         exact = FrozenVar.exactmatch(self, box, outgoingvarboxes, memo)
-        return exact and partialdatamatch
+        match = exact and partialdatamatch
+        if not memo.force_merge and not match:
+            from pypy.jit.timeshifter.rcontainer import VirtualContainer
+            if isinstance(box.content, VirtualContainer):
+                raise DontMerge
+        return match
 
 
 class FrozenPtrVirtual(FrozenValue):
@@ -440,12 +457,13 @@
         assert isinstance(box, PtrRedBox)
         if box.genvar:
             outgoingvarboxes.append(box)
-            return False
+            match = False
         else:
             assert box.content is not None
-            return self.fz_content.exactmatch(box.content, outgoingvarboxes,
+            match = self.fz_content.exactmatch(box.content, outgoingvarboxes,
                                               memo)
-
+        return match
+    
     def unfreeze(self, incomingvarboxes, memo):
         return self.fz_content.unfreeze(incomingvarboxes, memo)
 

Modified: pypy/dist/pypy/jit/timeshifter/test/test_portal.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_portal.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_portal.py	Sat Nov 25 18:27:54 2006
@@ -197,6 +197,43 @@
                                          policy=P_OOPSPEC)
         assert not res
 
+    def test_method_call_nonpromote(self):
+        class Base(object):
+            pass
+        class Int(Base):
+            def __init__(self, n):
+                self.n = n
+            def double(self):
+                return Int(self.n * 2)
+            def get(self):
+                return self.n
+        class Str(Base):
+            def __init__(self, s):
+                self.s = s
+            def double(self):
+                return Str(self.s + self.s)
+            def get(self):
+                return ord(self.s[4])
+
+        def ll_main(n):
+            if n > 0:
+                o = Int(n)
+            else:
+                o = Str('123')
+            return ll_function(o)
+
+        def ll_function(o):
+            hint(None, global_merge_point=True)
+            return o.double().get()
+
+        res = self.timeshift_from_portal(ll_main, ll_function, [5], policy=P_NOVIRTUAL)
+        assert res == 10
+        self.check_insns(indirect_call=2)
+
+        res = self.timeshift_from_portal(ll_main, ll_function, [0], policy=P_NOVIRTUAL)
+        assert res == ord('2')
+        self.check_insns(indirect_call=2)
+
     def test_method_call_promote(self):
         class Base(object):
             pass
@@ -236,7 +273,6 @@
         self.check_insns(indirect_call=0)
 
     def test_virt_obj_method_call_promote(self):
-        py.test.skip('WIP')
         class Base(object):
             pass
         class Int(Base):

Modified: pypy/dist/pypy/jit/timeshifter/test/test_promotion.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_promotion.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_promotion.py	Sat Nov 25 18:27:54 2006
@@ -185,44 +185,6 @@
         res = self.timeshift(ll_function, [100, 2], [], policy=P_NOVIRTUAL)
         assert res == ll_function(100, 2)
 
-
-    def test_method_call_nonpromote(self):
-        class Base(object):
-            pass
-        class Int(Base):
-            def __init__(self, n):
-                self.n = n
-            def double(self):
-                return Int(self.n * 2)
-            def get(self):
-                return self.n
-        class Str(Base):
-            def __init__(self, s):
-                self.s = s
-            def double(self):
-                return Str(self.s + self.s)
-            def get(self):
-                return int(self.s)
-
-        def ll_make(n):
-            if n > 0:
-                return Int(n)
-            else:
-                return Str('123')
-
-        def ll_function(n):
-            o = ll_make(n)
-            return o.double().get()
-
-        res = self.timeshift(ll_function, [5], [], policy=P_NOVIRTUAL)
-        assert res == 10
-        self.check_insns(indirect_call=2)
-
-        res = self.timeshift(ll_function, [0], [], policy=P_NOVIRTUAL)
-        assert res == 123123
-        self.check_insns(indirect_call=2)
-
-
     def test_mixed_merges(self):
         def ll_function(x, y, z, k):
             if x:



More information about the Pypy-commit mailing list