[pypy-svn] r29503 - in pypy/dist/pypy/jit: hintannotator timeshifter timeshifter/test

arigo at codespeak.net arigo at codespeak.net
Thu Jun 29 18:35:12 CEST 2006


Author: arigo
Date: Thu Jun 29 18:35:09 2006
New Revision: 29503

Added:
   pypy/dist/pypy/jit/timeshifter/test/test_tlr.py   (contents, props changed)
Modified:
   pypy/dist/pypy/jit/hintannotator/model.py
   pypy/dist/pypy/jit/timeshifter/oop.py
   pypy/dist/pypy/jit/timeshifter/rtimeshift.py
   pypy/dist/pypy/jit/timeshifter/rtyper.py
   pypy/dist/pypy/jit/timeshifter/timeshift.py
   pypy/dist/pypy/jit/timeshifter/vlist.py
Log:
(arre, pedronis, arigo)

Added a test: the TLR interpreter.  Lots of fixes, additions, and
head-scratching to make it pass.  Added minimal direct_call() support
(all-green only).

We have now turned the TLR interpreter into a compiler :-)



Modified: pypy/dist/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/dist/pypy/jit/hintannotator/model.py	(original)
+++ pypy/dist/pypy/jit/hintannotator/model.py	Thu Jun 29 18:35:09 2006
@@ -149,6 +149,14 @@
 
 class __extend__(SomeLLAbstractValue):
 
+    def define_unary(TYPE):
+        def var_unary(hs_v):
+            return SomeLLAbstractVariable(TYPE)
+        return var_unary
+
+    int_neg = define_unary(lltype.Signed)
+    uint_is_true = int_is_true = define_unary(lltype.Bool)
+
     def same_as(hs_v1):
         return hs_v1
 

Modified: pypy/dist/pypy/jit/timeshifter/oop.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/oop.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/oop.py	Thu Jun 29 18:35:09 2006
@@ -53,9 +53,6 @@
                                  None, None, [method])
             self.ll_handler = getattr(vmodule, method)
 
-    def _freeze_(self):
-        return True
-
     def residual_call(self, jitstate, argboxes):
         args_gv = self.args_gv[:]
         argpositions = self.argpositions

Modified: pypy/dist/pypy/jit/timeshifter/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtimeshift.py	Thu Jun 29 18:35:09 2006
@@ -761,6 +761,7 @@
     replace_memo = rvalue.copy_memo()
     for box in outgoingvarboxes:
         linkargs.append(box.getgenvar(jitstate))
+    for box in outgoingvarboxes:
         if box.is_constant():            # constant boxes considered immutable:
             box = box.copy(replace_memo) # copy to avoid patching the original
         box.genvar = rgenop.geninputarg(newblock, box.gv_type)

Modified: pypy/dist/pypy/jit/timeshifter/rtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rtyper.py	Thu Jun 29 18:35:09 2006
@@ -206,8 +206,17 @@
         assert isinstance(c_func, flowmodel.Constant)
         fnobj = c_func.value._obj
         if hasattr(fnobj._callable, 'oopspec'):
+            # special-cased call, for things like list methods
             hop.r_s_popfirstarg()
             return self.handle_highlevel_operation(fnobj, hop)
+        elif (originalconcretetype(hop.s_result) is not lltype.Void and
+              isinstance(hop.r_result, GreenRepr)):
+            # green-returning call, for now (XXX) we assume it's an
+            # all-green function that we can just call
+            for r_arg in hop.args_r:
+                assert isinstance(r_arg, GreenRepr)
+            v = hop.genop('direct_call', hop.args_v, hop.r_result.lowleveltype)
+            return v
         else:
             raise NotImplementedError("direct_call")
 
@@ -225,7 +234,19 @@
                 v = hop.inputconst(self.getredrepr(lltype.typeOf(obj)), obj)
             args_v.append(v)
 
+        # if the ll_handler() takes more arguments, it must be 'None' defaults.
+        # Pass them as constant Nones.
         ts = self.timeshifter
+        ll_handler = oopspecdesc.ll_handler
+        missing_args = ((ll_handler.func_code.co_argcount - 2) -
+                        len(oopspecdesc.argtuple))
+        assert missing_args >= 0
+        if missing_args > 0:
+            assert (ll_handler.func_defaults[-missing_args:] ==
+                    (None,) * missing_args)
+            ll_None = lltype.nullptr(ts.r_RedBox.lowleveltype.TO)
+            args_v.extend([hop.llops.genconst(ll_None)] * missing_args)
+
         args_s = [ts.s_RedBox] * len(args_v)
         RESULT = originalconcretetype(hop.s_result)
         if RESULT is lltype.Void:
@@ -233,12 +254,12 @@
         else:
             s_result = ts.s_RedBox
 
-        c_oopspecdesc = hop.inputconst(lltype.Void, oopspecdesc)
-        s_oopspecdesc = ts.rtyper.annotator.bookkeeper.immutablevalue(
-            oopspecdesc)
-
+        s_oopspecdesc  = ts.s_OopSpecDesc
+        ll_oopspecdesc = ts.annhelper.delayedconst(ts.r_OopSpecDesc,
+                                                   oopspecdesc)
+        c_oopspecdesc  = hop.llops.genconst(ll_oopspecdesc)
         v_jitstate = hop.llops.getjitstate()
-        return hop.llops.genmixlevelhelpercall(oopspecdesc.ll_handler,
+        return hop.llops.genmixlevelhelpercall(ll_handler,
                                       [ts.s_JITState, s_oopspecdesc] + args_s,
                                       [v_jitstate,    c_oopspecdesc] + args_v,
                                       s_result)
@@ -274,16 +295,11 @@
         graph = self.timeshifter.annhelper.getgraph(function, args_s, s_result)
         self.record_extra_call(graph) # xxx
 
-        rtyper = self.timeshifter.rtyper
-        ARGS = [rtyper.getrepr(s_arg).lowleveltype for s_arg in args_s]
-        RESULT = rtyper.getrepr(s_result).lowleveltype
-
-        F = lltype.FuncType(ARGS, RESULT)
-
-        fptr = lltype.functionptr(F, graph.name, graph=graph)
+        c = self.timeshifter.annhelper.graph2const(graph)
 
         # build the 'direct_call' operation
-        c = inputconst(lltype.Ptr(F), fptr)
+        rtyper = self.timeshifter.rtyper
+        RESULT = rtyper.getrepr(s_result).lowleveltype
         return self.genop('direct_call', [c]+args_v,
                           resulttype = RESULT)
 

Added: pypy/dist/pypy/jit/timeshifter/test/test_tlr.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/timeshifter/test/test_tlr.py	Thu Jun 29 18:35:09 2006
@@ -0,0 +1,11 @@
+from pypy.rpython.lltypesystem.rstr import string_repr
+from pypy.jit.timeshifter.test.test_timeshift import timeshift
+from pypy.jit.timeshifter.test.test_vlist import P_OOPSPEC
+
+from pypy.jit.tl import tlr
+
+
+def test_tlr():
+    bytecode = string_repr.convert_const(tlr.SQUARE)
+    insns, res = timeshift(tlr.interpret, [bytecode, 9], [0], policy=P_OOPSPEC)
+    assert res == 81

Modified: pypy/dist/pypy/jit/timeshifter/timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/timeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/timeshift.py	Thu Jun 29 18:35:09 2006
@@ -3,7 +3,7 @@
 from pypy.objspace.flow import model as flowmodel
 from pypy.annotation import model as annmodel
 from pypy.annotation import listdef, dictdef
-from pypy.jit.timeshifter import rvalue
+from pypy.jit.timeshifter import rvalue, oop
 from pypy.jit.timeshifter.rtimeshift import JITState
 from pypy.rpython import rmodel, rgenop, annlowlevel
 from pypy.rpython.lltypesystem import rtuple, rlist, rdict
@@ -26,6 +26,8 @@
 
         self.s_JITState, self.r_JITState = self.s_r_instanceof(JITState)
         self.s_RedBox, self.r_RedBox = self.s_r_instanceof(rvalue.RedBox)
+        self.s_OopSpecDesc, self.r_OopSpecDesc = self.s_r_instanceof(
+            oop.OopSpecDesc)
 
         getrepr = self.rtyper.getrepr
 
@@ -123,8 +125,14 @@
         return self.latestexitindex
 
     def timeshift(self):
-        for graph in self.hannotator.translator.graphs:
-            self.timeshift_graph(graph)
+        # XXX in-progress:
+        ##for graph in self.hannotator.translator.graphs:
+        ##    self.timeshift_graph(graph)
+
+        # instead:
+        graph = self.hannotator.translator.graphs[0]
+        self.timeshift_graph(graph)
+        
         # Annotate and rType the helpers found during timeshifting
         self.annhelper.finish()
 

Modified: pypy/dist/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/vlist.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/vlist.py	Thu Jun 29 18:35:09 2006
@@ -15,11 +15,8 @@
         self.build_newlist = LIST.list_builder.build_newlist
         self.build_setitem = LIST.list_builder.build_setitem
 
-    def _freeze_(self):
-        return True
-
-    def ll_factory(self):
-        vlist = VirtualList(self)
+    def factory(self, length, itembox):
+        vlist = VirtualList(self, length, itembox)
         box = rvalue.PtrRedBox(self.gv_ptrtype)
         box.content = vlist
         vlist.ownbox = box
@@ -62,10 +59,10 @@
 
 class VirtualList(AbstractContainer):
 
-    def __init__(self, typedesc):
+    def __init__(self, typedesc, length=0, itembox=None):
         self.typedesc = typedesc
-        self.item_boxes = []
-        # self.ownbox = ...    set in ll_factory
+        self.item_boxes = [itembox] * length
+        # self.ownbox = ...    set in factory()
 
     def enter_block(self, newblock, incoming, memo):
         contmemo = memo.containers
@@ -116,11 +113,12 @@
             self.ownbox = self.ownbox.replace(memo)
 
 
-def oop_newlist(jitstate, oopspecdesc, lengthbox):
-    assert lengthbox.is_constant()
-    length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
-    assert length == 0
-    return oopspecdesc.typedesc.ll_factory()
+def oop_newlist(jitstate, oopspecdesc, lengthbox, itembox=None):
+    if lengthbox.is_constant():
+        length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
+        if length == 0 or itembox is not None:
+            return oopspecdesc.typedesc.factory(length, itembox)
+    return oopspecdesc.residual_call(jitstate, [lengthbox, itembox])
 
 def oop_list_append(jitstate, oopspecdesc, selfbox, itembox):
     if isinstance(selfbox.content, VirtualList):
@@ -134,3 +132,10 @@
         return selfbox.content.item_boxes[index]
     else:
         return oopspecdesc.residual_call(jitstate, [selfbox, indexbox])
+
+def oop_list_setitem(jitstate, oopspecdesc, selfbox, indexbox, itembox):
+    if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
+        index = rvalue.ll_getvalue(indexbox, lltype.Signed)
+        selfbox.content.item_boxes[index] = itembox
+    else:
+        oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])



More information about the Pypy-commit mailing list