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

ac at codespeak.net ac at codespeak.net
Tue Jan 30 17:47:21 CET 2007


Author: ac
Date: Tue Jan 30 17:47:19 2007
New Revision: 37619

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/rvirtualizable.py
   pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
Log:
(pedronis, arre) Refactor to use frame places.

Modified: pypy/dist/pypy/jit/timeshifter/hrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/hrtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/hrtyper.py	Tue Jan 30 17:47:19 2007
@@ -156,44 +156,6 @@
         self.v_queue = varoftype(self.r_Queue.lowleveltype, 'queue')
         #self.void_red_repr = VoidRedRepr(self)
 
-        # XXX use helpers, factor out perhaps?
-        annhelper = self.annhelper
-        from pypy.rpython.lltypesystem.rvirtualizable import VABLERTIPTR
-        s_vablertiptr = annmodel.lltype_to_annotation(VABLERTIPTR)
-
-        s_gcref = annmodel.lltype_to_annotation(llmemory.GCREF)
-        from pypy.jit.timeshifter import rvirtualizable
-        def vrti_get_global_shape(vablerti):
-            vablerti = cast_base_ptr_to_instance(
-                         rvirtualizable.VirtualizableRTI,
-                         vablerti)
-            return vablerti.get_global_shape()
-        vrti_get_global_shape_ptr = annhelper.delayedfunction(
-                                        vrti_get_global_shape,
-                                        [s_vablertiptr],
-                                        annmodel.SomeInteger(),
-                                        needtype=True)
-        self.gv_vrti_get_global_shape_ptr = RGenOp.constPrebuiltGlobal(
-            vrti_get_global_shape_ptr)
-        self.vrti_get_global_shape_token = RGenOp.sigToken(
-                                  lltype.typeOf(vrti_get_global_shape_ptr).TO)
-
-
-        def vrti_read_forced(vablerti, bitkey):
-            vablerti = cast_base_ptr_to_instance(
-                     rvirtualizable.WithForcedStateVirtualizableRTI,
-                              vablerti)
-            return vablerti.read_forced(bitkey)
-
-        vrti_read_forced_ptr = annhelper.delayedfunction(vrti_read_forced,
-                              [s_vablertiptr, annmodel.SomeInteger()],
-                              s_gcref,
-                              needtype=True)
-        self.gv_vrti_read_forced_ptr = RGenOp.constPrebuiltGlobal(
-            vrti_read_forced_ptr)
-        self.vrti_read_forced_token = RGenOp.sigToken(
-                                     lltype.typeOf(vrti_read_forced_ptr).TO)
-
         # global state for the portal corresponding to this timeshifted world
         class PortalState(object):
             pass

Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py	Tue Jan 30 17:47:19 2007
@@ -54,11 +54,6 @@
                     immutable noidentity
                     materialize
                     fill_into
-
-                    vrti_get_global_shape_token
-                    gv_vrti_get_global_shape_ptr
-                    vrti_read_forced_token
-                    gv_vrti_read_forced_ptr
                  """.split()
                             
 
@@ -90,14 +85,7 @@
         self._define_fill_into()
         if self.immutable and self.noidentity:
             self._define_materialize()
-
-        # xxx
-        self.gv_vrti_get_global_shape_ptr = hrtyper.gv_vrti_get_global_shape_ptr
-        self.vrti_get_global_shape_token = hrtyper.vrti_get_global_shape_token
         
-        self.gv_vrti_read_forced_ptr = hrtyper.gv_vrti_read_forced_ptr
-        self.vrti_read_forced_token = hrtyper.vrti_read_forced_token
-
     def _compute_fielddescs(self, hrtyper):
         RGenOp = hrtyper.RGenOp
         TYPE = self.TYPE
@@ -239,7 +227,6 @@
 
         self._define_collect_residual_args()
 
-        self._define_getset_rti_ptrs(hrtyper)
         self._define_access_is_null(hrtyper)
 
 
@@ -308,22 +295,6 @@
         self.collect_residual_args = collect_residual_args
 
 
-
-    def _define_getset_rti_ptrs(self, hrtyper):
-        RGenOp = hrtyper.RGenOp
-        TOPPTR = self.access_desc.PTRTYPE
-        
-        def get_rti(base, frameinfo, frameindex):
-            struc = RGenOp.read_frame_var(TOPPTR, base, frameinfo, frameindex)
-            return struc.vable_rti
-
-        def set_rti(base, frameinfo, frameindex, new_vable_rti):
-            struc = RGenOp.read_frame_var(TOPPTR, base, frameinfo, frameindex)
-            struc.vable_rti = new_vable_rti
-
-        self.get_rti = get_rti
-        self.set_rti = set_rti
-
     def _define_access_is_null(self, hrtyper):
         RGenOp = hrtyper.RGenOp
         annhelper = hrtyper.annhelper        
@@ -600,6 +571,12 @@
         vrti = rvirtualizable.VirtualStructRTI(rgenop, bitmask)
         memo.containers[self] = vrti
 
+        builder = jitstate.curbuilder
+        place = builder.alloc_frame_place(typedesc.ptrkind,
+                                          typedesc.gv_null)
+        gv_forced = builder.genop_absorb_place(typedesc.ptrkind, place)
+        vrti.forced_place = place
+
         vars_gv = memo.framevars_gv
         varindexes = vrti.varindexes
         vrtis = vrti.vrtis
@@ -616,6 +593,10 @@
                 assert isinstance(content, VirtualStruct) # XXX for now
                 vrtis.append(content.make_rti(jitstate, memo))
                 j -= 1
+
+        self.content_boxes.append(rvalue.PtrRedBox(typedesc.ptrkind,
+                                                   gv_forced))
+                
         return vrti
 
     def reshape(self, jitstate, shapemask, memo):
@@ -628,14 +609,11 @@
         memo.bitcount += 1
 
         boxes = self.content_boxes
+        outside_box = boxes.pop()
         if bitmask&shapemask:
-            gv_vable_rti = memo.gv_vable_rti
-            gv_bitkey = builder.rgenop.genconst(bitmask)
-            gv_ptr = builder.genop_call(typedesc.vrti_read_forced_token,
-                                        typedesc.gv_vrti_read_forced_ptr,
-                                        [gv_vable_rti, gv_bitkey])
-            memo.forced.append((self, gv_ptr))
-
+            gv_forced = outside_box.genvar
+            memo.forced.append((self, gv_forced))
+            
         for box in boxes:
             if not box.genvar:
                 assert isinstance(box, rvalue.PtrRedBox)
@@ -644,7 +622,7 @@
                 content.reshape(jitstate, shapemask, memo)
 
 class VirtualizableStruct(VirtualStruct):
-
+    
     def force_runtime_container(self, jitstate):
         assert 0
 
@@ -699,15 +677,10 @@
         rgenop = jitstate.curbuilder.rgenop
         vable_rti = rvirtualizable.VirtualizableRTI(rgenop, 0)
         vable_rti.touch_update = typedesc.touch_update
+        vable_rti.shape_place = jitstate.shape_place
         memo.containers[self] = vable_rti
         
         vars_gv = memo.framevars_gv
-        vars_gv.append(gv_outside)
-        getset_rti = (memo.frameindex,
-                      typedesc.get_rti,
-                      typedesc.set_rti)
-        memo.vable_getset_rtis.append(getset_rti)
-        memo.frameindex += 1
         varindexes = vable_rti.varindexes
         vrtis = vable_rti.vrtis
         boxes = self.content_boxes
@@ -748,23 +721,16 @@
         access_token = typedesc.access_desc.fieldtoken
         builder.genop_setfield(access_token, gv_outside, typedesc.gv_access)
 
-    def after_residual_call(self, jitstate, gv_shape):
+    def after_residual_call(self, jitstate):
         typedesc = self.typedesc
         builder = jitstate.curbuilder
         gv_outside = self.content_boxes[-1].genvar
         if gv_outside is typedesc.gv_null:
-            return gv_shape
+            return
         assert isinstance(typedesc, VirtualizableStructTypeDesc)
         access_token = typedesc.access_desc.fieldtoken            
         gv_access_null = typedesc.access_desc.gv_default
         builder.genop_setfield(access_token, gv_outside, gv_access_null)
-        if gv_shape is None:
-            rti_token = typedesc.rti_desc.fieldtoken                
-            gv_vable_rti = builder.genop_getfield(rti_token, gv_outside)
-            tok = typedesc.vrti_get_global_shape_token
-            fn = typedesc.gv_vrti_get_global_shape_ptr
-            gv_shape = builder.genop_call(tok, fn, [gv_vable_rti])
-        return gv_shape
 
 
     def reshape(self, jitstate, shapemask, memo):
@@ -777,11 +743,7 @@
             return
         memo.containers[self] = None
         assert isinstance(typedesc, VirtualizableStructTypeDesc)
-        gv_vable_rti = memo.gv_vable_rti
-        if gv_vable_rti is None:
-            rti_token = typedesc.rti_desc.fieldtoken
-            gv_vable_rti = builder.genop_getfield(rti_token, gv_outside)
-            memo.gv_vable_rti = gv_vable_rti
+
         boxes = self.content_boxes
         nvirtual = 0
         for _, i in typedesc.redirected_fielddescs:

Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py	Tue Jan 30 17:47:19 2007
@@ -900,11 +900,14 @@
         virtualizables = self.virtualizables
         if virtualizables:
             builder = self.curbuilder
-            memo = rvalue.make_vinfo_memo()
+            memo = rvalue.make_vrti_memo()
             memo.bitcount = 0
             memo.frameindex = 0
             memo.framevars_gv = []
-            memo.vable_getset_rtis = []
+            shape_kind = builder.rgenop.kindToken(lltype.Signed)
+            gv_zero = builder.rgenop.genconst(0)
+            self.shape_place = builder.alloc_frame_place(shape_kind, gv_zero)
+            
             vable_rtis = []
             for virtualizable_box in virtualizables:
                 content = virtualizable_box.content
@@ -913,14 +916,12 @@
             assert memo.bitcount < 32
             gv_base = builder.genop_get_frame_base()
             frameinfo = builder.get_frame_info(memo.framevars_gv)
-            vable_getset_rtis = memo.vable_getset_rtis
             for i in range(len(virtualizables)):
                 vable_rti = vable_rtis[i]
                 if vable_rti is None:
                     continue
                 assert isinstance(vable_rti, rvirtualizable.VirtualizableRTI)
                 vable_rti.frameinfo = frameinfo
-                vable_rti.vable_getset_rtis = vable_getset_rtis
                 virtualizable_box = virtualizables[i]
                 content = virtualizable_box.content
                 assert isinstance(content, rcontainer.VirtualizableStruct)
@@ -929,13 +930,16 @@
     def after_residual_call(self):
         virtualizables = self.virtualizables
         builder = self.curbuilder
-        gv_shape = None
         if virtualizables:
             for virtualizable_box in virtualizables:
                 content = virtualizable_box.content
                 assert isinstance(content, rcontainer.VirtualizableStruct)
-                gv_shape = content.after_residual_call(self, gv_shape)
-        if gv_shape is None:
+                content.after_residual_call(self)
+            shape_kind = builder.rgenop.kindToken(lltype.Signed)
+            gv_shape = builder.genop_absorb_place(shape_kind,
+                                                  self.shape_place)
+            self.shape_place = None
+        else:
             gv_shape = builder.rgenop.genconst(0)
         return rvalue.IntRedBox(builder.rgenop.kindToken(lltype.Signed),
                                 gv_shape)
@@ -943,20 +947,24 @@
     def reshape(self, shapemask):
         virtualizables = self.virtualizables
         builder = self.curbuilder
-        if virtualizables and shapemask:
-            memo = rvalue.make_vinfo_memo()
+        if virtualizables:
+            memo = rvalue.make_vrti_memo()
             memo.bitcount = 0
-            memo.forced = []
-            memo.gv_vable_rti = None
+            if shapemask:
+                memo.forced = []
+            else:
+                memo.forced = None
+
             for virtualizable_box in virtualizables:
                 content = virtualizable_box.content
                 assert isinstance(content, rcontainer.VirtualizableStruct)
                 content.reshape(self, shapemask, memo)
 
-            for vstruct, gv_ptr in memo.forced:
-                vstruct.content_boxes = None
-                vstruct.ownbox.genvar = gv_ptr
-                vstruct.ownbox.content = None
+            if shapemask:
+                for vstruct, gv_ptr in memo.forced:
+                    vstruct.content_boxes = None
+                    vstruct.ownbox.genvar = gv_ptr
+                    vstruct.ownbox.content = None
                 
     def freeze(self, memo):
         result = FrozenJITState()

Modified: pypy/dist/pypy/jit/timeshifter/rvalue.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvalue.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rvalue.py	Tue Jan 30 17:47:19 2007
@@ -25,7 +25,7 @@
 def unfreeze_memo():
     return Memo()
 
-def make_vinfo_memo():
+def make_vrti_memo():
     return Memo()
 
 class DontMerge(Exception):

Modified: pypy/dist/pypy/jit/timeshifter/rvirtualizable.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rvirtualizable.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rvirtualizable.py	Tue Jan 30 17:47:19 2007
@@ -4,25 +4,27 @@
 from pypy.rlib.unroll import unrolling_iterable
 
 debug_print = lloperation.llop.debug_print
+debug_pdb = lloperation.llop.debug_pdb
 
-def define_touch_update(TOPPTR, fielddescs, access_touched):
-    fielddescs = unrolling_iterable(fielddescs)
+def define_touch_update(TOPPTR, redirected_fielddescs, access_touched):
+    redirected_fielddescs = unrolling_iterable(redirected_fielddescs)
 
     def touch_update(strucref):
         struc = lltype.cast_opaque_ptr(TOPPTR, strucref)
         vable_rti = struc.vable_rti
         vable_rti = cast_base_ptr_to_instance(VirtualizableRTI, vable_rti)
         vable_rti.touch(struc.vable_base)
-        
-        j = 0
-        for fielddesc, _ in fielddescs:
+        vable_base = struc.vable_base
+
+        j = -1
+        for fielddesc, _ in redirected_fielddescs:
+            j += 1
             if fielddesc.canbevirtual and fielddesc.gcref:
-                if vable_rti.is_field_virtual(j):
+                if vable_rti.is_field_virtual(vable_base, j):
                     continue
-            v = vable_rti.read_field(fielddesc, struc.vable_base, j)
+            v = vable_rti.read_field(fielddesc, vable_base, j)
             tgt = lltype.cast_pointer(fielddesc.PTRTYPE, struc)            
             setattr(tgt, fielddesc.fieldname, v)
-            j += 1
         ACCESSPTR = TOPPTR.TO.vable_access
         struc.vable_access = lltype.cast_pointer(ACCESSPTR, access_touched)
 
@@ -45,9 +47,10 @@
         if fielddesc.canbevirtual and fielddesc.gcref:
             vable_rti = struc.vable_rti
             vable_rti = cast_base_ptr_to_instance(VirtualizableRTI, vable_rti)
-            if vable_rti.is_field_virtual(j):
+            vable_base = struc.vable_base
+            if vable_rti.is_field_virtual(vable_base, j):
                 # this will force
-                s = vable_rti.read_field(fielddesc, struc.vable_base, j)
+                s = vable_rti.read_field(fielddesc, vable_base, j)
                 setattr(tgt, fielddesc.fieldname, s)
                 return s
         return getattr(tgt, fielddesc.fieldname)
@@ -87,44 +90,23 @@
         assert isinstance(T, lltype.Ptr)
         assert fielddesc.canbevirtual
         assert fielddesc.gcref
+        assert isinstance(vrti, VirtualStructRTI)
         return vrti._get_forced(vablerti, fielddesc, base)
     _read_field._annspecialcase_ = "specialize:arg(2)"
 
-    def _is_virtual(self, forcestate):
-        return self.bitmask not in forcestate
-
-    def _get_forced(self, vablerti, fielddesc, base):
-        T = fielddesc.RESTYPE
-        assert isinstance(T, lltype.Ptr)
-        forcestate = vablerti.getforcestate(base).forced
-        bitmask = self.bitmask
-        if bitmask in forcestate:
-            s = forcestate[bitmask] 
-            return lltype.cast_opaque_ptr(T, s)
-        S = T.TO
-        s = lltype.malloc(S)
-        sref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
-        forcestate[bitmask] = sref
-        fielddesc.fill_into(vablerti, s, base, self)
-        return s
-    _get_forced._annspecialcase_ = "specialize:arg(2)"
 
 class VirtualizableRTI(VirtualRTI):
-    _attrs_ = "frameinfo vable_getset_rtis touch_update".split()
-            
-    def get_global_shape(self):
-        return 0
+    _attrs_ = "frameinfo touch_update shape_place".split()
 
-    def is_field_virtual(self, index):
+    def is_field_virtual(self, base, index):
         frameindex = self.varindexes[index]
         if frameindex >= 0:
             return False
         index = -frameindex-1
         assert index >= 0
-        return self._is_field_virtual(index)
-
-    def _is_field_virtual(self, index):
-       return True
+        vrti = self.vrtis[index]
+        assert isinstance(vrti, VirtualStructRTI)
+        return vrti._is_virtual(self.get_shape(base))       
 
     def read_frame_var(self, T, base, frameindex):
         return self.rgenop.read_frame_var(T, base, self.frameinfo, frameindex)
@@ -134,20 +116,8 @@
         return self._read_field(self, fielddesc, base, index)
     read_field._annspecialcase_ = "specialize:arg(1)"
 
-    def getforcestate(self, base):
-        state = State()
-        for i, get, set in self.vable_getset_rtis:
-            p = get(base, self.frameinfo, i)
-            vablerti = cast_base_ptr_to_instance(VirtualizableRTI, p)
-            # xxx see below
-            wforcestate = WithForcedStateVirtualizableRTI(vablerti, state) 
-            p = cast_instance_to_base_ptr(wforcestate)
-            set(base, self.frameinfo, i, p)
-        return state
-
     def touch(self, base):
-        touched = self.getforcestate(base).touched
-        touched[self.bitmask] = None
+        self.set_shape_bits(base, self.bitmask)
 
     def touched_ptr_field(self, base, index):
         frameindex = self.varindexes[index]
@@ -155,47 +125,37 @@
             return
         posshift = -frameindex
         assert posshift > 0
-        touched = self.getforcestate(base).touched
-        touched[self.bitmask<<posshift] = None
+        self.set_shape_bits(base, self.bitmask << posshift)
 
+    def get_shape(self, base):
+        return self.rgenop.read_frame_place(lltype.Signed, base,
+                                            self.shape_place)
+
+    def set_shape(self, base, shapemask):
+        return self.rgenop.write_frame_place(lltype.Signed, base,
+                                            self.shape_place, shapemask)
 
-class State(object):
-    forced = {}
-    touched = {}
-
-class WithForcedStateVirtualizableRTI(VirtualizableRTI):
-    _attrs_ = "state"
-    state = None
-    
-    def __init__(self, vablerti, state):
-        self.rgenop = vablerti.rgenop
-        self.varindexes = vablerti.varindexes
-        self.vrtis = vablerti.vrtis # xxx what if these contain virtualizables 
-        self.frameinfo = vablerti.frameinfo
-        self.bitmask = vablerti.bitmask
-        self.state = state
-
-    def _is_field_virtual(self, index):
-       vinfo = self.vrtis[index]
-       return vinfo._is_virtual(self.state.forced)
-
-    def getforcestate(self, base):
-        return self.state
-
-    def get_global_shape(self):
-        assert self.state
-        bitmask = 0
-        for bitkey in self.state.forced:
-            bitmask |= bitkey
-        for bitkey in self.state.touched:
-            bitmask |= bitkey  
-        return bitmask
-
-    def read_forced(self, bitkey):
-        assert self.state
-        assert self.state.forced
-        return self.state.forced[bitkey]
+    def set_shape_bits(self, base, bitmask):
+        self.set_shape(base, bitmask | self.get_shape(base))
 
 
 class VirtualStructRTI(VirtualRTI):
-    pass
+    _attrs_ = "forced_place"
+
+    def _get_forced(self, vablerti, fielddesc, base):
+        T = fielddesc.RESTYPE
+        assert isinstance(T, lltype.Ptr)
+        shapemask = vablerti.get_shape(base)
+        bitmask = self.bitmask
+        if bitmask & shapemask:
+            return self.rgenop.read_frame_place(T, base, self.forced_place)
+        S = T.TO
+        s = lltype.malloc(S)
+        self.rgenop.write_frame_place(T, base, self.forced_place, s)
+        vablerti.set_shape(base, shapemask| bitmask)
+        fielddesc.fill_into(vablerti, s, base, self)
+        return s
+    _get_forced._annspecialcase_ = "specialize:arg(2)"
+
+    def _is_virtual(self, shapemask):
+        return bool(self.bitmask & shapemask)

Modified: pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py	Tue Jan 30 17:47:19 2007
@@ -813,7 +813,7 @@
             calls = self.count_direct_calls()
             call_count = sum([count for graph, count in calls.iteritems()
                               if not graph.name.startswith('rpyexc_')])
-            assert call_count == 3
+            assert call_count == 2
 
 
     def test_setting_pointer_in_residual_call(self):
@@ -913,8 +913,8 @@
     def test_inheritance_with_residual_call(self):
         class S(object):
             def __init__(self, x, y):
-                self.x = x
-                self.y = y
+                self.sx = x
+                self.sy = y
             
 
         class X(object):
@@ -935,8 +935,8 @@
             x = xy.x
             y = xy.y
             if x:
-                xy.x = s.x
-                xy.y = s.y
+                xy.x = s.sx
+                xy.y = s.sy
             if y:
                 xy.s = S(x, y)
    
@@ -944,7 +944,7 @@
             hint(None, global_merge_point=True)
             xy.s = S(sx, sy)
             g(xy)
-            return xy.x + xy.y * 16 + xy.s.x * 16 ** 2 + xy.s.y * 16 ** 3
+            return xy.x + xy.y * 16 + xy.s.sx * 16 ** 2 + xy.s.sy * 16 ** 3
 
         def main(x, y, sx, sy):
             X(0)



More information about the Pypy-commit mailing list