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

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Feb 11 14:15:50 CET 2008


Author: cfbolz
Date: Mon Feb 11 14:15:48 2008
New Revision: 51382

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_vlist.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py
Log:
some support for virtual lists


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	Mon Feb 11 14:15:48 2008
@@ -4,6 +4,7 @@
 from pypy.jit.hintannotator.model import originalconcretetype
 from pypy.jit.hintannotator import model as hintmodel
 from pypy.jit.timeshifter import rtimeshift, rvalue, rcontainer, exception
+from pypy.jit.timeshifter import oop
 from pypy.jit.timeshifter.greenkey import KeyDesc
 from pypy.jit.rainbow.interpreter import JitCode, JitInterpreter
 from pypy.translator.backendopt.removenoops import remove_same_as
@@ -14,10 +15,10 @@
 class BytecodeWriter(object):
     def __init__(self, t, hannotator, RGenOp):
         self.translator = t
-        self.annotator = t.annotator
+        self.rtyper = hannotator.base_translator.rtyper
         self.hannotator = hannotator
         etrafo = hannotator.exceptiontransformer
-        type_system = hannotator.base_translator.rtyper.type_system.name
+        type_system = self.rtyper.type_system.name
         self.exceptiondesc = exception.ExceptionDesc(
             RGenOp, etrafo, type_system, False)
         self.interpreter = JitInterpreter(self.exceptiondesc)
@@ -44,6 +45,7 @@
         self.fielddescs = []
         self.arrayfielddescs = []
         self.interiordescs = []
+        self.oopspecdescs = []
         self.called_bytecodes = []
         self.num_mergepoints = 0
         self.graph_color = self.graph_calling_color(graph)
@@ -71,6 +73,8 @@
         self.arrayfielddesc_positions = {}
         # mapping (TYPE, path) to index
         self.interiordesc_positions = {}
+        # mapping (fnobj, can_raise) to index
+        self.oopspecdesc_positions = {}
         # mapping graphs to index
         self.graph_positions = {}
         # mapping fnobjs to index
@@ -91,6 +95,7 @@
                           self.fielddescs,
                           self.arrayfielddescs,
                           self.interiordescs,
+                          self.oopspecdescs,
                           self.called_bytecodes,
                           self.num_mergepoints,
                           self.graph_color,
@@ -352,6 +357,17 @@
         self.arrayfielddesc_positions[TYPE] = result
         return result
 
+    def oopspecdesc_position(self, fnobj, canraise):
+        key = fnobj, canraise
+        if key in self.oopspecdesc_positions:
+            return self.oopspecdesc_positions[key]
+        oopspecdesc = oop.OopSpecDesc(self.RGenOp, self.rtyper,
+                                      fnobj, canraise)
+        result = len(self.oopspecdescs)
+        self.oopspecdescs.append(oopspecdesc)
+        self.oopspecdesc_positions[key] = result
+        return result
+
     def graph_position(self, graph):
         if graph in self.graph_positions:
             return self.graph_positions[graph]
@@ -478,6 +494,45 @@
 
     def serialize_op_direct_call(self, op):
         kind, exc = self.guess_call_kind(op)
+        print op, kind, exc
+        if kind == "oopspec":
+            from pypy.jit.timeshifter.oop import Index
+            fnobj = op.args[0].value._obj
+            oopspecdescindex = self.oopspecdesc_position(fnobj, exc)
+            oopspecdesc = self.oopspecdescs[oopspecdescindex]
+            opargs = op.args[1:]
+            args_v = []
+            args = []
+            for obj in oopspecdesc.argtuple:
+                if isinstance(obj, Index):
+                    v = opargs[obj.n]
+                else:
+                    v = flowmodel.Constant(obj, lltype.typeOf(obj))
+                args_v.append(v)
+                args.append(self.serialize_oparg("red", v))
+
+            ll_handler = oopspecdesc.ll_handler
+            couldfold = oopspecdesc.couldfold
+            missing_args = ((ll_handler.func_code.co_argcount - 3) -
+                            len(oopspecdesc.argtuple))
+            assert missing_args >= 0
+            if missing_args > 0:
+                assert (ll_handler.func_defaults[-missing_args:] ==
+                        (None,) * missing_args)
+
+            if oopspecdesc.is_method:
+                hs_self = self.hannotator.binding(
+                    opargs[oopspecdesc.argtuple[0].n])
+                deepfrozen = hs_self.deepfrozen
+            else:
+                deepfrozen = False
+
+            self.emit("red_oopspec_call_%s" % (len(args), ))
+            self.emit(oopspecdescindex)
+            self.emit(deepfrozen)
+            self.emit(*args)
+            self.register_redvar(op.result)
+            return
         targets = dict(self.graphs_from(op))
         assert len(targets) == 1
         targetgraph, = targets.values()

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	Mon Feb 11 14:15:48 2008
@@ -19,8 +19,8 @@
 
     def __init__(self, name, code, constants, typekinds, redboxclasses,
                  keydescs, structtypedescs, fielddescs, arrayfielddescs,
-                 interiordescs, called_bytecodes, num_mergepoints, graph_color,
-                 nonrainbow_functions, is_portal):
+                 interiordescs, oopspecdescs, called_bytecodes, num_mergepoints,
+                 graph_color, nonrainbow_functions, is_portal):
         self.name = name
         self.code = code
         self.constants = constants
@@ -31,6 +31,7 @@
         self.fielddescs = fielddescs
         self.arrayfielddescs = arrayfielddescs
         self.interiordescs = interiordescs
+        self.oopspecdescs = oopspecdescs
         self.called_bytecodes = called_bytecodes
         self.num_mergepoints = num_mergepoints
         self.graph_color = graph_color
@@ -166,6 +167,10 @@
         assert gv.is_const
         self.frame.local_green.append(gv)
 
+    def green_result_from_red(self, box):
+        assert box.is_constant()
+        self.green_result(box.getgenvar(self.jitstate))
+
     def newjitstate(self, newjitstate):
         self.jitstate = newjitstate
         self.queue = None
@@ -319,14 +324,43 @@
         # XXX all this jitstate.greens business is a bit messy
         self.green_result(self.jitstate.greens[0])
 
+    def opimpl_red_oopspec_call_1(self):
+        oopspecindex = self.load_2byte()
+        deepfrozen = self.load_bool()
+        arg1 = self.get_redarg()
+        oopspec = self.frame.bytecode.oopspecdescs[oopspecindex]
+        result = oopspec.ll_handler(self.jitstate, oopspec, deepfrozen, arg1)
+        self.red_result(result)
+
+    def opimpl_red_oopspec_call_2(self):
+        oopspecindex = self.load_2byte()
+        deepfrozen = self.load_bool()
+        arg1 = self.get_redarg()
+        arg2 = self.get_redarg()
+        oopspec = self.frame.bytecode.oopspecdescs[oopspecindex]
+        result = oopspec.ll_handler(self.jitstate, oopspec, deepfrozen, arg1, arg2)
+        self.red_result(result)
+
+    def opimpl_red_oopspec_call_3(self):
+        oopspecindex = self.load_2byte()
+        deepfrozen = self.load_bool()
+        arg1 = self.get_redarg()
+        arg2 = self.get_redarg()
+        arg3 = self.get_redarg()
+        oopspec = self.frame.bytecode.oopspecdescs[oopspecindex]
+        result = oopspec.ll_handler(self.jitstate, oopspec, deepfrozen, arg1, arg2, arg3)
+        self.red_result(result)
+
 
     # exceptions
 
     def opimpl_read_exctype(self):
-        XXX
+        box = rtimeshift.getexctypebox(self.jitstate)
+        self.red_result(box)
 
     def opimpl_read_excvalue(self):
-        XXX
+        box = rtimeshift.getexcvaluebox(self.jitstate)
+        self.red_result(box)
 
     def opimpl_write_exctype(self):
         typebox = self.get_redarg()
@@ -411,8 +445,7 @@
         indexboxes = self.get_red_varargs()
         resultbox = interiordesc.gengetinteriorfield(self.jitstate, deepfrozen,
                                                      structbox, indexboxes)
-        assert resultbox.is_constant()
-        self.green_result(resultbox.getgenvar(self.jitstate))
+        self.green_result_from_red(resultbox)
 
     def opimpl_red_setinteriorfield(self):
         destbox = self.get_redarg()
@@ -437,8 +470,8 @@
         indexboxes = self.get_red_varargs()
         resultbox = interiordesc.gengetinteriorarraysize(
             self.jitstate, arraybox, indexboxes)
-        assert resultbox.is_constant()
-        self.green_result(resultbox.getgenvar(self.jitstate))
+        self.green_result_from_red(resultbox)
+
     # ____________________________________________________________
     # construction-time interface
 

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_vlist.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_vlist.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_vlist.py	Mon Feb 11 14:15:48 2008
@@ -4,7 +4,6 @@
 from pypy.rlib.jit import hint
 
 P_OOPSPEC = HintAnnotatorPolicy(novirtualcontainer=True, oopspec=True)
-py.test.skip("implement me")
 
 
 class TestVList(AbstractInterpretationTest):
@@ -66,6 +65,7 @@
         self.check_insns({'int_is_true': 1})
 
     def test_force(self):
+        py.test.skip("implement me")
         def ll_function(n):
             lst = []
             lst.append(n)
@@ -134,6 +134,7 @@
         self.check_insns({})
 
     def test_frozen_list(self):
+        py.test.skip("implement me")
         lst = [5, 7, 9]
         def ll_function(x):
             mylist = hint(lst, deepfreeze=True)
@@ -146,6 +147,7 @@
         self.check_insns({})
 
     def test_frozen_list_indexerror(self):
+        py.test.skip("implement me")
         lst = [5, 7, 9]
         def ll_function(x):
             mylist = hint(lst, deepfreeze=True)
@@ -161,6 +163,7 @@
         self.check_insns({})
 
     def test_bogus_index_while_compiling(self):
+        py.test.skip("implement me")
         class Y:
             pass
 

Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/oop.py	Mon Feb 11 14:15:48 2008
@@ -20,7 +20,7 @@
 
     do_call = None
 
-    def __init__(self, hrtyper, fnobj, can_raise):
+    def __init__(self, RGenOp, rtyper, fnobj, can_raise):
         ll_func = fnobj._callable
         FUNCTYPE = lltype.typeOf(fnobj)
         nb_args = len(FUNCTYPE.ARGS)
@@ -34,8 +34,8 @@
         if args.strip() == ',':
             args = '()'
         argnames = ll_func.func_code.co_varnames[:nb_args]
-        d = dict(zip(argnames, [Index(n) for n in range(nb_args)]))
-        self.argtuple = eval(args, d)
+        argname2index = dict(zip(argnames, [Index(n) for n in range(nb_args)]))
+        self.argtuple = eval(args, argname2index)
         # end of rather XXX'edly hackish parsing
 
         OOPARGTYPES = []
@@ -54,7 +54,6 @@
             if ARGTYPE is not lltype.Void:
                 self.residualargsources.append(arg_llsig_to_oopsig[i])
 
-        RGenOp = hrtyper.RGenOp
         self.args_gv = [None] * nb_args
         fnptr = fnobj._as_ptr()
         self.gv_fnptr = RGenOp.constPrebuiltGlobal(fnptr)
@@ -86,7 +85,7 @@
 
         vmodule = __import__('pypy.jit.timeshifter.v%s' % (typename,),
                              None, None, [method])
-        self.typedesc = vmodule.TypeDesc(hrtyper, SELFTYPE)
+        self.typedesc = vmodule.TypeDesc(RGenOp, rtyper, SELFTYPE)
         self.ll_handler = getattr(vmodule, method)
         self.couldfold = getattr(self.ll_handler, 'couldfold', False)
 

Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/vdict.py	Mon Feb 11 14:15:48 2008
@@ -269,7 +269,7 @@
 def oop_newdict(jitstate, oopspecdesc):
     return oopspecdesc.typedesc.factory()
 
-def oop_dict_setitem(jitstate, oopspecdesc, selfbox, keybox, valuebox):
+def oop_dict_setitem(jitstate, oopspecdesc, deepfrozen, selfbox, keybox, valuebox):
     content = selfbox.content
     if isinstance(content, AbstractVirtualDict) and keybox.is_constant():
         content.setitem(keybox, valuebox)

Modified: pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/timeshifter/vlist.py	Mon Feb 11 14:15:48 2008
@@ -27,9 +27,7 @@
 class ListTypeDesc(object):
     __metaclass__ = cachedtype
 
-    def __init__(self, hrtyper, LIST):
-        RGenOp = hrtyper.RGenOp
-        rtyper = hrtyper.rtyper
+    def __init__(self, RGenOp, rtyper, LIST):
         self.LIST = LIST
         self.LISTPTR = lltype.Ptr(LIST)
         self.ptrkind = RGenOp.kindToken(self.LISTPTR)
@@ -269,13 +267,13 @@
                 content.reshape(jitstate, shapemask, memo)
 
 
-def oop_newlist(jitstate, oopspecdesc, lengthbox, itembox=None):
+def oop_newlist(jitstate, oopspecdesc, deepfrozen, lengthbox, itembox=None):
     if lengthbox.is_constant():
         length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
         return oopspecdesc.typedesc.factory(length, itembox)
     return oopspecdesc.residual_call(jitstate, [lengthbox, itembox])
 
-def oop_list_copy(jitstate, oopspecdesc, selfbox):
+def oop_list_copy(jitstate, oopspecdesc, deepfrozen, selfbox):
     content = selfbox.content
     if isinstance(content, VirtualList):
         copybox = oopspecdesc.typedesc.factory(0, None)
@@ -304,14 +302,14 @@
                                          deepfrozen=deepfrozen)
 oop_list_nonzero.couldfold = True
 
-def oop_list_append(jitstate, oopspecdesc, selfbox, itembox):
+def oop_list_append(jitstate, oopspecdesc, deepfrozen, selfbox, itembox):
     content = selfbox.content
     if isinstance(content, VirtualList):
         content.item_boxes.append(itembox)
     else:
         oopspecdesc.residual_call(jitstate, [selfbox, itembox])
 
-def oop_list_insert(jitstate, oopspecdesc, selfbox, indexbox, itembox):
+def oop_list_insert(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox, itembox):
     content = selfbox.content
     if isinstance(content, VirtualList) and indexbox.is_constant():
         index = rvalue.ll_getvalue(indexbox, lltype.Signed)
@@ -321,7 +319,7 @@
     else:
         oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
 
-def oop_list_concat(jitstate, oopspecdesc, selfbox, otherbox):
+def oop_list_concat(jitstate, oopspecdesc, deepfrozen, selfbox, otherbox):
     content = selfbox.content
     if isinstance(content, VirtualList):
         assert isinstance(otherbox, rvalue.PtrRedBox)
@@ -335,7 +333,7 @@
             return newbox
     return oopspecdesc.residual_call(jitstate, [selfbox, otherbox])
 
-def oop_list_pop(jitstate, oopspecdesc, selfbox, indexbox=None):
+def oop_list_pop(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox=None):
     content = selfbox.content
     if indexbox is None:
         if isinstance(content, VirtualList):
@@ -355,7 +353,7 @@
             return oopspecdesc.residual_exception(jitstate, IndexError)
     return oopspecdesc.residual_call(jitstate, [selfbox, indexbox])
 
-def oop_list_reverse(jitstate, oopspecdesc, selfbox):
+def oop_list_reverse(jitstate, oopspecdesc, deepfrozen, selfbox):
     content = selfbox.content
     if isinstance(content, VirtualList):
         content.item_boxes.reverse()
@@ -375,7 +373,7 @@
                                          deepfrozen=deepfrozen)
 oop_list_getitem.couldfold = True
 
-def oop_list_setitem(jitstate, oopspecdesc, selfbox, indexbox, itembox):
+def oop_list_setitem(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox, itembox):
     content = selfbox.content
     if isinstance(content, VirtualList) and indexbox.is_constant():
         index = rvalue.ll_getvalue(indexbox, lltype.Signed)
@@ -386,7 +384,7 @@
     else:
         oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
 
-def oop_list_delitem(jitstate, oopspecdesc, selfbox, indexbox):
+def oop_list_delitem(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox):
     content = selfbox.content
     if isinstance(content, VirtualList) and indexbox.is_constant():
         index = rvalue.ll_getvalue(indexbox, lltype.Signed)



More information about the Pypy-commit mailing list