[pypy-svn] r23136 - in pypy/dist/pypy: jit jit/test rpython

arigo at codespeak.net arigo at codespeak.net
Wed Feb 8 03:24:12 CET 2006


Author: arigo
Date: Wed Feb  8 03:24:06 2006
New Revision: 23136

Added:
   pypy/dist/pypy/jit/rtimeshift.py
Modified:
   pypy/dist/pypy/jit/hinttimeshift.py
   pypy/dist/pypy/jit/test/test_hint_timeshift.py
   pypy/dist/pypy/rpython/rgenop.py
Log:
(pedronis, arigo)

Some progress in the Time Shifter part of the JIT.
Still completely basic.



Modified: pypy/dist/pypy/jit/hinttimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/hinttimeshift.py	(original)
+++ pypy/dist/pypy/jit/hinttimeshift.py	Wed Feb  8 03:24:06 2006
@@ -1,19 +1,30 @@
 from pypy.jit import hintmodel
 from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.rmodel import inputconst
+from pypy.rpython.rtyper import LowLevelOpList
+from pypy.rpython.rstr import string_repr
+from pypy.rpython import rgenop
 from pypy.objspace.flow import model as flowmodel
 from pypy.annotation import model as annmodel
+from pypy.jit.rtimeshift import STATE_PTR, REDBOX_PTR 
+from pypy.jit import rtimeshift
 
 # ___________________________________________________________
 
+def ll_fixed_items(l):
+    return l
+
+VARLIST = lltype.Ptr(lltype.GcArray(rgenop.CONSTORVAR,
+                                    adtmeths = {
+                                        "ll_items": ll_fixed_items,
+                                    }))
+
 class HintTimeshift(object):
     
-    def __init__(self, hannotator):
+    def __init__(self, hannotator, rtyper):
         self.hannotator = hannotator
-        self.STATE = lltype.GcForwardReference()
-        self.STATE_PTR = lltype.Ptr(self.STATE)
-        self.REDBOX = lltype.GcForwardReference()
-        self.REDBOX_PTR = lltype.Ptr(self.REDBOX)
-        
+        self.rtyper = rtyper
+
     def timeshift(self):
         for graph in self.hannotator.translator.graphs:
             self.timeshift_graph(graph)
@@ -25,24 +36,26 @@
     def timeshift_block(self, block):
         if not block.exits:   # ignore return/except blocks
             return  # XXX for now
-        jitstate = flowmodel.Variable('jitstate')
-        jitstate.concretetype = self.STATE_PTR
+        self.jitstate = flowmodel.Variable('jitstate')
+        self.jitstate.concretetype = STATE_PTR
 
         self.varcolor = {}
+        self.varconcretetype = {}
 
         def introduce_var(v):
+            self.varconcretetype[v] = v.concretetype
             if self.is_green(v):
                 color = "green"
             else:
                 color = "red"
-                v.concretetype = self.REDBOX_PTR
+                v.concretetype = REDBOX_PTR
             self.varcolor[v] = color
 
         for inputarg in block.inputargs:
             introduce_var(inputarg)
 
         # look for "red" operations
-        newops = []
+        newops = LowLevelOpList(self.rtyper)
         for op in block.operations:
             green = True
             for arg in op.args:
@@ -59,12 +72,17 @@
         block.operations[:] = newops
 
         # pass 'jitstate' as an extra argument around the whole graph
-        block.inputargs.insert(0, jitstate)
+        block.inputargs.insert(0, self.jitstate)
         for link in block.exits:
-            link.args.insert(0, jitstate)
+            link.args.insert(0, self.jitstate)
 
     def timeshift_op(self, op, newops):
-        pass
+        handler = getattr(self, 'tshift_' + op.opname, self.default_tshift)
+        v_res = handler(op, newops)
+        if v_res is not None:
+            assert v_res.concretetype == op.result.concretetype
+            op1 = flowmodel.SpaceOperation('same_as', [v_res], op.result)
+            newops.append(op1)
 
     def is_green(self, var):
         hs_var = self.hannotator.binding(var)
@@ -74,3 +92,42 @@
             return hs_var.eager_concrete or hs_var.is_fixed()
         else:
             return False
+
+    def get_genop_var(self, var, llops):
+        color = self.varcolor.get(var, "green")
+        if color == "red":
+            return llops.gendirectcall(rtimeshift.ll_gvar_from_redbox,
+                                       self.jitstate, var)
+        elif color == "green":
+            return llops.gendirectcall(rtimeshift.ll_gvar_from_constant,
+                                       self.jitstate, var)
+        else:
+            raise NotImplementedError(color)
+
+    # ____________________________________________________________
+
+    def default_tshift(self, op, llops):
+        # by default, a red operation converts all its arguments to
+        # genop variables, and emits a call to a helper that will generate
+        # the same operation at run-time
+        # XXX constant propagate if possible        
+        v_args = llops.genop('malloc_varsize',
+                             [inputconst(lltype.Void, VARLIST.TO),
+                              inputconst(lltype.Signed, len(op.args))],
+                             resulttype = VARLIST)
+        for i, arg in enumerate(op.args):
+            v_gvar = self.get_genop_var(arg, llops)
+            llops.genop('setarrayitem', [v_args,
+                                         inputconst(lltype.Signed, i),
+                                         v_gvar])
+        v_restype = inputconst(lltype.Void, self.varconcretetype[op.result])
+        v_res = llops.gendirectcall(rtimeshift.ll_generate_operation,
+                                    self.jitstate, opname2vstr(op.opname),
+                                    v_args, v_restype)
+        assert self.varcolor[op.result] == "red"   # XXX for now
+        return v_res
+
+
+def opname2vstr(name):
+    lls = string_repr.convert_const(name)
+    return inputconst(string_repr.lowleveltype, lls)

Added: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/rtimeshift.py	Wed Feb  8 03:24:06 2006
@@ -0,0 +1,22 @@
+from pypy.rpython.lltypesystem import lltype
+from pypy.rpython import rgenop
+
+
+STATE = lltype.GcStruct("jitstate", ("curblock", rgenop.BLOCK))
+STATE_PTR = lltype.Ptr(STATE)
+
+REDBOX = lltype.GcStruct("redbox", ("genvar", rgenop.CONSTORVAR))
+REDBOX_PTR = lltype.Ptr(REDBOX)
+
+
+def ll_gvar_from_redbox(jitstate, box):
+    return box.genvar
+
+def ll_gvar_from_const(jitstate, value):
+    return rgenop.genconst(jitstate.curblock, value)
+
+def ll_generate_operation(jitstate, opname, args, RESULTTYPE):
+    gvar = rgenop.genop(jitstate.curblock, opname, args, RESULTTYPE)
+    box = lltype.malloc(REDBOX)
+    box.genvar = gvar
+    return box

Modified: pypy/dist/pypy/jit/test/test_hint_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_timeshift.py	(original)
+++ pypy/dist/pypy/jit/test/test_hint_timeshift.py	Wed Feb  8 03:24:06 2006
@@ -14,7 +14,7 @@
 P_OOPSPEC = AnnotatorPolicy()
 P_OOPSPEC.oopspec = True
 
-def hannotate(func, argtypes, policy=None, annotator=False):
+def hannotate(func, argtypes, policy=None):
     # build the normal ll graphs for ll_function
     t = TranslationContext()
     a = t.buildannotator()
@@ -31,17 +31,14 @@
     t = hannotator.translator
     if conftest.option.view:
         t.view()
-    if annotator:
-        return hs, hannotator
-    else:
-        return hs
+    return hs, hannotator, rtyper
 
 
 def test_simple_fixed():
     def ll_function(x, y):
         return hint(x + y, concrete=True)
-    hs, ha  = hannotate(ll_function, [int, int], annotator=True)
-    htshift = HintTimeshift(ha)
+    hs, ha, rtyper = hannotate(ll_function, [int, int])
+    htshift = HintTimeshift(ha, rtyper)
     htshift.timeshift()
     if conftest.option.view:
         ha.translator.view()
@@ -50,7 +47,7 @@
     #py.test.skip("in-progress")
     def ll_function(x, y):
         return x + y
-    hs, ha  = hannotate(ll_function, [int, int], annotator=True)
-    htshift = HintTimeshift(ha)
+    hs, ha, rtyper = hannotate(ll_function, [int, int])
+    htshift = HintTimeshift(ha, rtyper)
     htshift.timeshift()
 

Modified: pypy/dist/pypy/rpython/rgenop.py
==============================================================================
--- pypy/dist/pypy/rpython/rgenop.py	(original)
+++ pypy/dist/pypy/rpython/rgenop.py	Wed Feb  8 03:24:06 2006
@@ -188,17 +188,18 @@
 from pypy.rpython.extfunctable import declaretype, declareptrtype, declare
 
 blocktypeinfo = declaretype(flowmodel.Block, "Block")
-vartypeinfo   = declareptrtype(flowmodel.Variable, "VarOrConst")
-consttypeinfo = declareptrtype(flowmodel.Constant, "VarOrConst")
-consttypeinfo.set_lltype(vartypeinfo.get_lltype())   # force same lltype
+consttypeinfo = declareptrtype(flowmodel.Constant, "ConstOrVar")
+vartypeinfo   = declareptrtype(flowmodel.Variable, "ConstOrVar")
+vartypeinfo.set_lltype(consttypeinfo.get_lltype())   # force same lltype
 linktypeinfo  = declareptrtype(flowmodel.Link, "Link")
 
-CONSTORVAR = consttypeinfo.get_lltype()
+CONSTORVAR = lltype.Ptr(consttypeinfo.get_lltype())
 BLOCKCONTAINERTYPE = blocktypeinfo.get_lltype()
-LINKTYPE = linktypeinfo.get_lltype()
+BLOCK = lltype.Ptr(BLOCKCONTAINERTYPE)
+LINK = lltype.Ptr(linktypeinfo.get_lltype())
 
 fieldnames = ['item%d' % i for i in range(2)]
-lltypes = [lltype.Ptr(LINKTYPE)]*2
+lltypes = [LINK]*2
 fields = tuple(zip(fieldnames, lltypes))    
 LINKPAIR = lltype.GcStruct('tuple2', *fields)
 
@@ -219,8 +220,8 @@
 # annotations
 from pypy.annotation import model as annmodel
 
-s_ConstOrVar = annmodel.SomeExternalObject(flowmodel.Variable)
-s_Link = annmodel.SomeExternalObject(flowmodel.Link)
+s_ConstOrVar = annmodel.SomePtr(CONSTORVAR)#annmodel.SomeExternalObject(flowmodel.Variable)
+s_Link = annmodel.SomePtr(LINK)#annmodel.SomeExternalObject(flowmodel.Link)
 s_LinkPair = annmodel.SomePtr(lltype.Ptr(LINKPAIR))
 
 setannotation(initblock, None)



More information about the Pypy-commit mailing list