[pypy-svn] r51284 - in pypy/branch/jit-refactoring/pypy/jit: rainbow rainbow/test timeshifter

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Feb 5 12:04:09 CET 2008


Author: cfbolz
Date: Tue Feb  5 12:04:07 2008
New Revision: 51284

Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/rcontainer.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/rtimeshift.py
Log:
support for red get/setinteriorfield and getinteriorarraysize


Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/codewriter.py	Tue Feb  5 12:04:07 2008
@@ -69,6 +69,8 @@
         self.fielddesc_positions = {}
         # mapping ARRAYS to index
         self.arrayfielddesc_positions = {}
+        # mapping (TYPE, path) to index
+        self.interiordesc_positions = {}
         # mapping graphs to index
         self.graph_positions = {}
         # mapping fnobjs to index
@@ -409,7 +411,7 @@
             key = (PTRTYPE.TO, tuple(path))
             if key in self.interiordesc_positions:
                 return self.interiordesc_positions[key]
-            desc = rcontainer.InteriorDesc(self.RGenOp, PTRTYPE.TO, tuple(path)),
+            desc = rcontainer.InteriorDesc(self.RGenOp, PTRTYPE.TO, tuple(path))
             result = len(self.interiordescs)
             self.interiordescs.append(desc)
             return (result, indices_v)
@@ -466,6 +468,9 @@
                 result.append(self.serialize_oparg(color, v))
         return result
 
+    def serialize_op_debug_assert(self, op):
+        pass
+
     def serialize_op_direct_call(self, op):
         targets = dict(self.graphs_from(op))
         assert len(targets) == 1
@@ -636,6 +641,67 @@
         self.emit("red_getarraysize", arrayindex, fielddescindex)
         self.register_redvar(op.result)
 
+    def serialize_op_getinteriorfield(self, op):
+        structvar = op.args[0]
+        PTRTYPE = structvar.concretetype
+        # no virtualizable access read here
+        assert not PTRTYPE.TO._hints.get('virtualizable', False)
+
+        # non virtual case
+        interiordescindex, indices_v = self.interiordesc(
+                op, PTRTYPE, len(op.args) - 1)
+        if interiordescindex == -1:    # Void field
+            return None
+        structindex = self.serialize_oparg("red", structvar)
+        deepfrozen = self.hannotator.binding(structvar).deepfrozen
+        indexes = []
+        for arg in indices_v:
+            indexes.append(self.serialize_oparg("red", arg))
+        self.emit("red_getinteriorfield", structindex, interiordescindex,
+                  deepfrozen)
+        self.emit(len(indexes))
+        self.emit(*indexes)
+        self.register_redvar(op.result)
+
+    def serialize_op_setinteriorfield(self, op):
+        structvar = op.args[0]
+        valuevar = op.args[-1]
+        PTRTYPE = structvar.concretetype
+        # non virtual case
+        interiordescindex, indices_v = self.interiordesc(
+                op, PTRTYPE, len(op.args) - 2)
+        structindex = self.serialize_oparg("red", structvar)
+        indexes = []
+        for arg in indices_v:
+            indexes.append(self.serialize_oparg("red", arg))
+        valueindex = self.serialize_oparg("red", valuevar)
+        self.emit("red_setinteriorfield", structindex, interiordescindex)
+        self.emit(len(indexes))
+        self.emit(*indexes)
+        self.emit(valueindex)
+
+    def serialize_op_getinteriorarraysize(self, op):
+        structvar = op.args[0]
+        PTRTYPE = structvar.concretetype
+        color = self.opcolor(op)
+        # non virtual case
+        interiordescindex, indices_v = self.interiordesc(
+                op, PTRTYPE, len(op.args) - 1)
+        assert interiordescindex != -1
+        structindex = self.serialize_oparg(color, structvar)
+        indexes = []
+        for arg in indices_v:
+            indexes.append(self.serialize_oparg(color, arg))
+        self.emit("%s_getinteriorarraysize" % color, structindex,
+                  interiordescindex)
+        self.emit(len(indexes))
+        self.emit(*indexes)
+        if color == "red":
+            self.register_redvar(op.result)
+        else:
+            self.register_greenvar(op.result)
+
+
     # call handling
 
     def graphs_from(self, spaceop):

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/interpreter.py	Tue Feb  5 12:04:07 2008
@@ -394,6 +394,37 @@
         resbox = rtimeshift.gengetarraysize(self.jitstate, fielddesc, arraybox)
         self.red_result(resbox)
 
+    def opimpl_red_getinteriorfield(self):
+        structbox = self.get_redarg()
+        interiordesc = self.frame.bytecode.interiordescs[self.load_2byte()]
+        deepfrozen = self.load_bool()
+        indexboxes = self.get_red_varargs()
+        resultbox = interiordesc.gengetinteriorfield(self.jitstate, deepfrozen,
+                                                     structbox, indexboxes)
+        self.red_result(resultbox)
+
+    def opimpl_red_setinteriorfield(self):
+        destbox = self.get_redarg()
+        interiordesc = self.frame.bytecode.interiordescs[self.load_2byte()]
+        indexboxes = self.get_red_varargs()
+        valuebox = self.get_redarg()
+        interiordesc.gensetinteriorfield(self.jitstate, destbox, valuebox, indexboxes)
+
+    def opimpl_red_getinteriorarraysize(self):
+        arraybox = self.get_redarg()
+        interiordesc = self.frame.bytecode.interiordescs[self.load_2byte()]
+        indexboxes = self.get_red_varargs()
+        resultbox = interiordesc.gengetinteriorarraysize(
+            self.jitstate, arraybox, indexboxes)
+        self.red_result(resultbox)
+
+    def opimpl_green_getinteriorarraysize(self):
+        arraygenconst = self.get_greenarg()
+        interiordesc = self.frame.bytecode.interiordescs[self.load_2byte()]
+        indexgenconsts = self.get_green_varargs()
+        resultbox = interiordesc.gengetinteriorarraysize(
+            self.jitstate, arraybox, indexboxes)
+        self.red_result(resultbox)
     # ____________________________________________________________
     # construction-time interface
 

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py	Tue Feb  5 12:04:07 2008
@@ -11,6 +11,7 @@
 from pypy.jit.timeshifter import rtimeshift, rvalue
 from pypy.rpython.lltypesystem import lltype, rstr
 from pypy.rpython.llinterp import LLInterpreter
+from pypy.rpython.module.support import LLSupport
 from pypy.annotation import model as annmodel
 from pypy.objspace.flow.model import summary
 from pypy.rlib.jit import hint
@@ -712,7 +713,7 @@
                 pc += 1
             return acc
         ll_plus_minus.convert_arguments = [LLSupport.to_rstr, int, int]
-        res = self.interpret(ll_plus_minus, ["+-+", 0, 2], [0], inline=100000)
+        res = self.interpret(ll_plus_minus, ["+-+", 0, 2], [0])
         assert res == ll_plus_minus("+-+", 0, 2)
         self.check_insns({'int_add': 2, 'int_sub': 1})
 
@@ -742,7 +743,6 @@
         assert res == 3
 
     def test_red_array(self):
-        py.test.skip("arrays and structs are not working")
         A = lltype.GcArray(lltype.Signed)
         def ll_function(x, y, n):
             a = lltype.malloc(A, 2)
@@ -750,22 +750,19 @@
             a[1] = y
             return a[n]*len(a)
 
-        res = self.interpret(ll_function, [21, -21, 0], [],
-                             policy=P_NOVIRTUAL)
+        res = self.interpret(ll_function, [21, -21, 0], [])
         assert res == 42
         self.check_insns({'malloc_varsize': 1,
                           'setarrayitem': 2, 'getarrayitem': 1,
                           'getarraysize': 1, 'int_mul': 1})
 
-        res = self.interpret(ll_function, [21, -21, 1], [],
-                             policy=P_NOVIRTUAL)
+        res = self.interpret(ll_function, [21, -21, 1], [])
         assert res == -42
         self.check_insns({'malloc_varsize': 1,
                           'setarrayitem': 2, 'getarrayitem': 1,
                           'getarraysize': 1, 'int_mul': 1})
 
     def test_red_struct_array(self):
-        py.test.skip("arrays and structs are not working")
         S = lltype.Struct('s', ('x', lltype.Signed))
         A = lltype.GcArray(S)
         def ll_function(x, y, n):
@@ -774,15 +771,13 @@
             a[1].x = y
             return a[n].x*len(a)
 
-        res = self.interpret(ll_function, [21, -21, 0], [],
-                             policy=P_NOVIRTUAL)
+        res = self.interpret(ll_function, [21, -21, 0], [])
         assert res == 42
         self.check_insns({'malloc_varsize': 1,
                           'setinteriorfield': 2, 'getinteriorfield': 1,
                           'getarraysize': 1, 'int_mul': 1})
 
-        res = self.interpret(ll_function, [21, -21, 1], [],
-                             policy=P_NOVIRTUAL)
+        res = self.interpret(ll_function, [21, -21, 1], [])
         assert res == -42
         self.check_insns({'malloc_varsize': 1,
                           'setinteriorfield': 2, 'getinteriorfield': 1,
@@ -790,7 +785,6 @@
 
 
     def test_red_varsized_struct(self):
-        py.test.skip("arrays and structs are not working")
         A = lltype.Array(lltype.Signed)
         S = lltype.GcStruct('S', ('foo', lltype.Signed), ('a', A))
         def ll_function(x, y, n):
@@ -800,14 +794,12 @@
             s.a[1] = y
             return s.a[n]*s.foo
 
-        res = self.interpret(ll_function, [21, -21, 0], [],
-                             policy=P_NOVIRTUAL)
+        res = self.interpret(ll_function, [21, -21, 0], [])
         assert res == 42
         self.check_insns(malloc_varsize=1,
                          getinteriorarraysize=1)
 
-        res = self.interpret(ll_function, [21, -21, 1], [],
-                             policy=P_NOVIRTUAL)
+        res = self.interpret(ll_function, [21, -21, 1], [])
         assert res == -42
         self.check_insns(malloc_varsize=1,
                          getinteriorarraysize=1)

Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/rcontainer.py	Tue Feb  5 12:04:07 2008
@@ -375,7 +375,7 @@
             immutable = LASTCONTAINER._hints.get('immutable', False)
             getinterior_initial = make_interior_getter(fielddescs[:-1])
 
-            def gengetinteriorfield(jitstate, deepfrozen, argbox, *indexboxes):
+            def gengetinteriorfield(jitstate, deepfrozen, argbox, indexboxes):
                 if (immutable or deepfrozen) and argbox.is_constant():
                     ptr = rvalue.ll_getvalue(argbox, PTRTYPE)
                     if ptr:    # else don't constant-fold the segfault...
@@ -395,7 +395,7 @@
                             # constant-folding: success
                             assert i == len(indexboxes)
                             return rvalue.ll_fromvalue(jitstate, ptr)
-                argbox = getinterior_initial(jitstate, argbox, *indexboxes)
+                argbox = getinterior_initial(jitstate, argbox, indexboxes)
                 if lastoffset is None:      # getarrayitem
                     indexbox = indexboxes[-1]
                     genvar = jitstate.curbuilder.genop_getarrayitem(
@@ -406,8 +406,8 @@
                 else:  # getfield
                     return argbox.op_getfield(jitstate, lastfielddesc)
 
-            def gensetinteriorfield(jitstate, destbox, valuebox, *indexboxes):
-                destbox = getinterior_initial(jitstate, destbox, *indexboxes)
+            def gensetinteriorfield(jitstate, destbox, valuebox, indexboxes):
+                destbox = getinterior_initial(jitstate, destbox, indexboxes)
                 if lastoffset is None:      # setarrayitem
                     indexbox = indexboxes[-1]
                     genvar = jitstate.curbuilder.genop_setarrayitem(
@@ -427,7 +427,7 @@
             arrayfielddesc = ArrayFieldDesc(RGenOp, TYPE)
             getinterior_all = make_interior_getter(fielddescs)
 
-            def gengetinteriorarraysize(jitstate, argbox, *indexboxes):
+            def gengetinteriorarraysize(jitstate, argbox, indexboxes):
                 if argbox.is_constant():
                     ptr = rvalue.ll_getvalue(argbox, PTRTYPE)
                     if ptr:    # else don't constant-fold the segfault...
@@ -447,7 +447,7 @@
                             # constant-folding: success
                             assert i == len(indexboxes)
                             return rvalue.ll_fromvalue(jitstate, len(ptr))
-                argbox = getinterior_all(jitstate, argbox, *indexboxes)
+                argbox = getinterior_all(jitstate, argbox, indexboxes)
                 genvar = jitstate.curbuilder.genop_getarraysize(
                     arrayfielddesc.arraytoken,
                     argbox.getgenvar(jitstate))
@@ -460,7 +460,7 @@
 
 
 def make_interior_getter(fielddescs, _cache={}):
-    # returns a 'getinterior(jitstate, argbox, *indexboxes)' function
+    # returns a 'getinterior(jitstate, argbox, indexboxes)' function
     key = tuple(fielddescs)
     try:
         return _cache[key]
@@ -469,7 +469,7 @@
             (fielddesc, isinstance(fielddesc, ArrayFieldDesc))
             for fielddesc in fielddescs])
 
-        def getinterior(jitstate, argbox, *indexboxes):
+        def getinterior(jitstate, argbox, indexboxes):
             i = 0
             for fielddesc, is_array in unroll_fielddescs:
                 if is_array:    # array substruct

Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/rtimeshift.py	Tue Feb  5 12:04:07 2008
@@ -209,17 +209,6 @@
     return rvalue.IntRedBox(fielddesc.indexkind, genvar)
 
 
-def ll_gengetinteriorfield(jitstate, deepfrozen, interiordesc,
-                           argbox, *indexboxes):
-    return interiordesc.gengetinteriorfield(jitstate, deepfrozen,
-                                            argbox, *indexboxes)
-
-def ll_gensetinteriorfield(jitstate, interiordesc, destbox,
-                           valuebox, *indexboxes):
-    interiordesc.gensetinteriorfield(jitstate, destbox, valuebox, *indexboxes)
-
-def ll_gengetinteriorarraysize(jitstate, interiordesc, argbox, *indexboxes):
-    return interiordesc.gengetinteriorarraysize(jitstate, argbox, *indexboxes)
 
 
 def genptrnonzero(jitstate, argbox, reverse):



More information about the Pypy-commit mailing list