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

arigo at codespeak.net arigo at codespeak.net
Wed Feb 8 18:57:30 CET 2006


Author: arigo
Date: Wed Feb  8 18:57:26 2006
New Revision: 23154

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

Make the graph-producing graphs actually runnable.
(The next goal is to make them produce actually runnable graphs :-)



Modified: pypy/dist/pypy/jit/hinttimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/hinttimeshift.py	(original)
+++ pypy/dist/pypy/jit/hinttimeshift.py	Wed Feb  8 18:57:26 2006
@@ -24,36 +24,27 @@
     def __init__(self, hannotator, rtyper):
         self.hannotator = hannotator
         self.rtyper = rtyper
+        self.varcolor = {}
+        self.varconcretetype = {}
 
     def timeshift(self):
         for graph in self.hannotator.translator.graphs:
             self.timeshift_graph(graph)
+        # RType the helpers found during timeshifting
+        self.rtyper.specialize_more_blocks()
 
     def timeshift_graph(self, graph):
         for block in graph.iterblocks():
             self.timeshift_block(block)
 
     def timeshift_block(self, block):
-        if not block.exits:   # ignore return/except blocks
-            return  # XXX for now
+        for inputarg in block.inputargs:
+            self.introduce_var(inputarg)
+        if not block.exits:
+            return    # nothing else to do
         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 = REDBOX_PTR
-            self.varcolor[v] = color
-
-        for inputarg in block.inputargs:
-            introduce_var(inputarg)
-
         # look for "red" operations
         newops = LowLevelOpList(self.rtyper)
         for op in block.operations:
@@ -61,7 +52,7 @@
             for arg in op.args:
                 if self.varcolor.get(arg, "green") != "green":
                     green = False
-            introduce_var(op.result)
+            self.introduce_var(op.result)
             if green and self.varcolor[op.result] == "green":
                 # XXX check for side effect ops
                 newops.append(op)
@@ -74,7 +65,8 @@
         # pass 'jitstate' as an extra argument around the whole graph
         block.inputargs.insert(0, self.jitstate)
         for link in block.exits:
-            link.args.insert(0, self.jitstate)
+            if link.target.exits:  # not if going to the return/except block
+                link.args.insert(0, self.jitstate)
 
     def timeshift_op(self, op, newops):
         handler = getattr(self, 'tshift_' + op.opname, self.default_tshift)
@@ -84,6 +76,15 @@
             op1 = flowmodel.SpaceOperation('same_as', [v_res], op.result)
             newops.append(op1)
 
+    def introduce_var(self, v):
+        self.varconcretetype[v] = v.concretetype
+        if self.is_green(v):
+            color = "green"
+        else:
+            color = "red"
+            v.concretetype = REDBOX_PTR
+        self.varcolor[v] = color
+
     def is_green(self, var):
         hs_var = self.hannotator.binding(var)
         if hs_var == annmodel.s_ImpossibleValue:

Modified: pypy/dist/pypy/jit/rtimeshift.py
==============================================================================
--- pypy/dist/pypy/jit/rtimeshift.py	(original)
+++ pypy/dist/pypy/jit/rtimeshift.py	Wed Feb  8 18:57:26 2006
@@ -20,3 +20,13 @@
     box = lltype.malloc(REDBOX)
     box.genvar = gvar
     return box
+
+def ll_setup_jitstate():
+    jitstate = lltype.malloc(STATE)
+    jitstate.curblock = rgenop.newblock()
+    return jitstate
+
+def ll_input_redbox(jitstate, TYPE):
+    box = lltype.malloc(REDBOX)
+    box.genvar = rgenop.geninputarg(jitstate.curblock, TYPE)
+    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 18:57:26 2006
@@ -4,20 +4,21 @@
 from pypy.jit.hintbookkeeper import HintBookkeeper
 from pypy.jit.hintmodel import *
 from pypy.jit.hinttimeshift import HintTimeshift
+from pypy.jit import rtimeshift
+from pypy.jit.test.test_llabstractinterp import annotation
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.objectmodel import hint
 from pypy.annotation import model as annmodel
-from pypy.annotation.policy import AnnotatorPolicy
+from pypy.rpython.llinterp import LLInterpreter
+from pypy.objspace.flow.model import checkgraph
 from pypy import conftest
 
 
-P_OOPSPEC = AnnotatorPolicy()
-P_OOPSPEC.oopspec = True
-
-def hannotate(func, argtypes, policy=None):
+def hannotate(func, values, policy=None):
     # build the normal ll graphs for ll_function
     t = TranslationContext()
     a = t.buildannotator()
+    argtypes = [annotation(a, x) for x in values]
     a.build_types(func, argtypes)
     rtyper = t.buildrtyper()
     rtyper.specialize()
@@ -32,21 +33,40 @@
         hannotator.translator.view()
     return hs, hannotator, rtyper
 
-def timeshift(ll_function, argtypes):
-    hs, ha, rtyper = hannotate(ll_function, argtypes)
+def timeshift(ll_function, values):
+    hs, ha, rtyper = hannotate(ll_function, values)
     htshift = HintTimeshift(ha, rtyper)
     htshift.timeshift()
     t = rtyper.annotator.translator
-    t.graphs.extend(ha.translator.graphs)
+    for graph in ha.translator.graphs:
+        checkgraph(graph)
+        t.graphs.append(graph)
     if conftest.option.view:
         t.view()
+    # run the time-shifted graph-producing graphs
+    graph1 = ha.translator.graphs[0]
+    jitstate = rtimeshift.ll_setup_jitstate()
+    graph1args = [jitstate]
+    assert len(graph1.getargs()) == 1 + len(values)
+    for v, llvalue in zip(graph1.getargs()[1:], values):
+        color = htshift.varcolor[v]
+        if color == "green":
+            graph1args.append(llvalue)
+        elif color == "red":
+            box = rtimeshift.ll_input_redbox(jitstate, v.concretetype)
+            graph1args.append(box)
+        else:
+            raise NotImplementedError(color)
+    llinterp = LLInterpreter(rtyper)
+    result1 = llinterp.eval_graph(graph1, graph1args)
+    return result1, jitstate
 
 def test_simple_fixed():
     def ll_function(x, y):
         return hint(x + y, concrete=True)
-    timeshift(ll_function, [int, int])
+    timeshift(ll_function, [5, 7])
 
 def test_simple():
     def ll_function(x, y):
         return x + y
-    timeshift(ll_function, [int, int])
+    timeshift(ll_function, [5, 7])



More information about the Pypy-commit mailing list