[pypy-svn] r25235 - pypy/branch/jit-timeshifter-refactoring/timeshifter

pedronis at codespeak.net pedronis at codespeak.net
Sun Apr 2 20:27:45 CEST 2006


Author: pedronis
Date: Sun Apr  2 20:27:44 2006
New Revision: 25235

Modified:
   pypy/branch/jit-timeshifter-refactoring/timeshifter/rcontainer.py
   pypy/branch/jit-timeshifter-refactoring/timeshifter/rtimeshift.py
   pypy/branch/jit-timeshifter-refactoring/timeshifter/rvalue.py
Log:
(arre, pedronis)

first pass at implementing copy, freeze and exactmatch for virtual structures, their frozen version respectively. 



Modified: pypy/branch/jit-timeshifter-refactoring/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-timeshifter-refactoring/timeshifter/rcontainer.py	(original)
+++ pypy/branch/jit-timeshifter-refactoring/timeshifter/rcontainer.py	Sun Apr  2 20:27:44 2006
@@ -3,7 +3,7 @@
 from pypy.rpython import rgenop
 from pypy.jit.timeshifter import rvalue
 
-class AbstractContainer(rvalue.Memoizable):
+class AbstractContainer(object):
     pass
 
 # ____________________________________________________________
@@ -138,6 +138,32 @@
         rgenop.genop(jitstate.curblock, 'setfield', op_args,
                      rgenop.gv_Void)        
 
+class FrozenVirtualStruct(AbstractContainer):
+
+    def exactmatch(self, vstruct, outgoingvarboxes, memo):
+        contmemo = memo.containers
+        if self in contmemo:
+            return vstruct is contmemo[self]
+        if vstruct in contmemo:
+            return contmemo[vstruct] is self 
+        contmemo[self] = vstruct
+        contmemo[vstruct] = self
+        self_length = len(self.fz_content_boxes)
+        vstruct_length = len(vstruct.content_boxes)
+        if self_length != vstruct_length:
+            return False
+        self_boxes = self.fz_content_boxes
+        vstruct_boxes = vstruct.content_boxes
+        fullmatch = True
+        for i in range(self_length):
+            if not self_boxes[i].exactmatch(vstruct_boxes[i],
+                                            outgoingvarboxes,
+                                            memo):
+                fullmatch = False
+        return fullmatch
+
+        
+
 class VirtualStruct(AbstractContainer):
 
     def __init__(self, typedesc):
@@ -147,8 +173,9 @@
                               for desc in typedesc.fielddescs]
 
     def enter_block(self, newblock, incoming, memo):
-        if self not in memo:
-            memo[self] = None
+        contmemo = memo.containers
+        if self not in contmemo:
+            contmemo[self] = None
             for box in self.content_boxes:
                 box.enter_block(newblock, incoming, memo)
 
@@ -174,3 +201,25 @@
             fielddesc.generate_set(jitstate, genvar, box)
 
         return genvar
+
+    def freeze(self, memo):
+        contmemo = memo.containers
+        try:
+            return contmemo[self]
+        except KeyError:
+            result = contmemo[self] = FrozenVirtualStruct()
+            frozens = [box.freeze(memo) for box in self.content_boxes]
+            result.fz_content_boxes = frozens
+            return result
+        
+    def copy(self, memo):
+        contmemo = memo.containers
+        try:
+            return contmemo[self]
+        except KeyError:
+            result = contmemo[self] = VirtualStruct(self.typedesc)
+            boxcopies = []
+            for box in self.content_boxes:
+                boxcopies.append(box.copy(memo))
+            result.content_boxes = boxcopies
+            return result

Modified: pypy/branch/jit-timeshifter-refactoring/timeshifter/rtimeshift.py
==============================================================================
--- pypy/branch/jit-timeshifter-refactoring/timeshifter/rtimeshift.py	(original)
+++ pypy/branch/jit-timeshifter-refactoring/timeshifter/rtimeshift.py	Sun Apr  2 20:27:44 2006
@@ -718,9 +718,9 @@
 
 def retrieve_jitstate_for_merge(states_dic, jitstate, key, redboxes):
     if key not in states_dic:
-        memo = {}
+        memo = rvalue.freeze_memo()
         frozens = [redbox.freeze(memo) for redbox in redboxes]
-        memo = {}
+        memo = rvalue.exactmatch_memo()
         outgoingvarboxes = []
         for i in range(len(redboxes)):
             res = frozens[i].exactmatch(redboxes[i], outgoingvarboxes, memo)
@@ -737,7 +737,7 @@
         return jitstate
 
     frozens, oldblock = states_dic[key]
-    memo = {}
+    memo = rvalue.exactmatch_memo()
     outgoingvarboxes = []
     exactmatch = True
     for i in range(len(redboxes)):
@@ -765,7 +765,7 @@
     rgenop.closelink(link, linkargs, newblock)
     jitstate.curblock = newblock
     #jitstate.curoutgoinglink = lltype.nullptr(rgenop.LINK.TO)
-    memo = {}
+    memo = rvalue.freeze_memo()
     frozens = [redbox.freeze(memo) for redbox in redboxes]
     states_dic[key] = frozens, newblock
     return jitstate
@@ -793,7 +793,7 @@
 def enter_block(jitstate, redboxes):
     newblock = rgenop.newblock()
     incoming = []
-    memo = {}
+    memo = rvalue.enter_block_memo()
     for i in range(len(redboxes)):
         redboxes[i].enter_block(newblock, incoming, memo)
     rgenop.closelink(jitstate.curoutgoinglink, incoming, newblock)
@@ -804,7 +804,7 @@
 def dyn_enter_block(jitstate, redboxes):
     newblock = rgenop.newblock()
     incoming = []
-    memo = {}
+    memo = rvalue.enter_block_memo()
     for i in range(len(redboxes)):
         redboxes[i].enter_block(newblock, incoming, memo)
     rgenop.closelink(jitstate.curoutgoinglink, incoming, newblock)
@@ -827,7 +827,7 @@
         later_jitstate = jitstate.copystate()
         jitstate.curoutgoinglink = true_link
         later_jitstate.curoutgoinglink = false_link
-        memo = {}
+        memo = rvalue.Memo()
         redboxcopies = [redbox.copy(memo) for redbox in redboxes]        
         jitstate.split_queue.append((exitindex, later_jitstate, redboxcopies))
         return True
@@ -867,7 +867,7 @@
     for link, redbox in return_queue:
         newblock = rgenop.newblock()
         incoming = []
-        memo = {}
+        memo = rvalue.enter_block_memo()
         redbox.enter_block(newblock, incoming, memo)
         jitstate.curblock = newblock
         gv_retval = redbox.getgenvar(jitstate)

Modified: pypy/branch/jit-timeshifter-refactoring/timeshifter/rvalue.py
==============================================================================
--- pypy/branch/jit-timeshifter-refactoring/timeshifter/rvalue.py	(original)
+++ pypy/branch/jit-timeshifter-refactoring/timeshifter/rvalue.py	Sun Apr  2 20:27:44 2006
@@ -1,10 +1,24 @@
 from pypy.rpython import rgenop
 from pypy.rpython.lltypesystem import lltype, llmemory
 
-class Memoizable(object):
-    pass
+class Memo(object):
+    _annspecialcase_ = 'specialize:ctr_location'
 
-class RedBox(Memoizable):
+    def __init__(self):
+        self.boxes = {}
+        self.containers = {}
+
+def enter_block_memo():
+    return Memo()
+
+def freeze_memo():
+    return Memo()
+
+def exactmatch_memo():
+    return Memo()
+
+
+class RedBox(object):
 
     def __init__(self, gv_type, genvar=rgenop.nullvar):
         assert rgenop.isconst(gv_type)   # temporary?
@@ -24,6 +38,7 @@
         return self.genvar
 
     def enter_block(self, newblock, incoming, memo):
+        memo = memo.boxes
         if not self.is_constant() and self not in memo:
             incoming.append(self.genvar)
             memo[self] = None
@@ -58,6 +73,7 @@
     "A red box that contains a constant integer-like value."
 
     def copy(self, memo):
+        memo = memo.boxes
         try:
             return memo[self]
         except KeyError:
@@ -65,6 +81,7 @@
             return result
 
     def freeze(self, memo):
+        memo = memo.boxes
         try:
             return memo[self]
         except KeyError:
@@ -80,6 +97,7 @@
     "A red box that contains a constant double-precision floating point value."
 
     def copy(self, memo):
+        memo = memo.boxes
         try:
             return memo[self]
         except KeyError:
@@ -87,6 +105,7 @@
             return result
 
     def freeze(self, memo):
+        memo = memo.boxes
         try:
             return memo[self]
         except KeyError:
@@ -111,29 +130,31 @@
             return RedBox.__repr__(self)
 
     def copy(self, memo):
+        boxmemo = memo.boxes
         try:
-            return memo[self]
+            return boxmemo[self]
         except KeyError:
             result = PtrRedBox(self.gv_type, self.genvar)
-            memo[self] = result
+            boxmemo[self] = result
             if self.content:
                 result.content = self.content.copy(memo)
             return result
 
     def freeze(self, memo):
+        boxmemo = memo.boxes
         try:
-            return memo[self]
+            return boxmemo[self]
         except KeyError:
             if self.content:
                 result = FrozenPtrVirtual()
-                memo[self] = result
+                boxmemo[self] = result
                 result.fz_content = self.content.freeze(memo)
             else:
                 if self.is_constant():
                     result = FrozenPtrConst(self.genvar)
                 else:
                     result = FrozenPtrVar()
-                memo[self] = result
+                boxmemo[self] = result
             return result
 
     def getgenvar(self, jitstate):
@@ -189,6 +210,7 @@
             return box
 
     def exactmatch(self, box, outgoingvarboxes, memo):
+        memo = memo.boxes
         if self not in memo:
             memo[self] = box
             outgoingvarboxes.append(box)
@@ -233,6 +255,7 @@
             return box
 
     def exactmatch(self, box, outgoingvarboxes, memo):
+        memo = memo.boxes
         if self not in memo:
             memo[self] = box
             outgoingvarboxes.append(box)
@@ -277,6 +300,7 @@
             return box
 
     def exactmatch(self, box, outgoingvarboxes, memo):
+        memo = memo.boxes
         if self not in memo:
             memo[self] = box
             outgoingvarboxes.append(box)
@@ -304,5 +328,8 @@
             outgoingvarboxes.append(box)
             return False
         else:
-            return self.fz_content.exactmatch(box.content, outgoingvarboxes,
-                                              memo)
+            result = self.fz_content.exactmatch(box.content, outgoingvarboxes,
+                                                memo)
+            if not result:
+                outgoingvarboxes.append(box)
+            return result



More information about the Pypy-commit mailing list