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

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Feb 4 02:45:08 CET 2008


Author: cfbolz
Date: Mon Feb  4 02:45:07 2008
New Revision: 51234

Modified:
   pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py
   pypy/branch/jit-refactoring/pypy/jit/timeshifter/rtimeshift.py
Log:
first test about yellow calls is passing


Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/bytecode.py	Mon Feb  4 02:45:07 2008
@@ -6,6 +6,7 @@
 from pypy.jit.hintannotator import model as hintmodel
 from pypy.jit.timeshifter import rtimeshift, rvalue
 from pypy.jit.timeshifter.greenkey import KeyDesc, empty_key, GreenKey
+from pypy.translator.backendopt.removenoops import remove_same_as
 
 class JitCode(object):
     """
@@ -70,6 +71,7 @@
     def bytecode_loop(self):
         while 1:
             bytecode = self.load_2byte()
+            assert bytecode >= 0
             result = self.opcode_implementations[bytecode](self)
             if result is STOP:
                 return
@@ -79,21 +81,23 @@
     def dispatch(self):
         is_portal = self.frame.bytecode.is_portal
         graph_color = self.frame.bytecode.graph_color
-        newjitstate = rtimeshift.dispatch_next(self.queue)
+        queue = self.queue
+        newjitstate = rtimeshift.dispatch_next(queue)
         resumepoint = rtimeshift.getresumepoint(newjitstate)
         self.newjitstate(newjitstate)
         if resumepoint == -1:
             if graph_color == "red":
                 newjitstate = rtimeshift.leave_graph_red(
-                        self.queue, is_portal)
+                        queue, is_portal)
+            elif graph_color == "yellow":
+                newjitstate = rtimeshift.leave_graph_yellow(queue)
             elif graph_color == "green":
                 XXX
             elif graph_color == "gray":
                 assert not is_portal
-                newjitstate = rtimeshift.leave_graph_gray(
-                        self.queue)
+                newjitstate = rtimeshift.leave_graph_gray(queue)
             else:
-                assert 0, "unknown graph color %s" % (color, )
+                assert 0, "unknown graph color %s" % (graph_color, )
 
             self.newjitstate(newjitstate)
             if newjitstate is None or is_portal:
@@ -152,8 +156,12 @@
 
     def newjitstate(self, newjitstate):
         self.jitstate = newjitstate
+        self.queue = None
         if newjitstate is not None:
-            self.frame = newjitstate.frame
+            frame = newjitstate.frame
+            self.frame = frame
+            if frame is not None:
+                self.queue = frame.dispatchqueue
         else:
             self.frame = None
 
@@ -192,8 +200,11 @@
         rtimeshift.save_return(self.jitstate)
         return self.dispatch()
 
-    def opimpl_green_return(self):
-        XXX
+    def opimpl_yellow_return(self):
+        # save the greens to make the return value findable by collect_split
+        rtimeshift.save_greens(self.jitstate, self.frame.local_green)
+        rtimeshift.save_return(self.jitstate)
+        return self.dispatch()
 
     def opimpl_make_new_redvars(self):
         self.frame.local_boxes = self.get_red_varargs()
@@ -247,6 +258,27 @@
         function = self.frame.bytecode.nonrainbow_functions[index]
         function(self, greenargs, redargs)
 
+    def opimpl_yellow_direct_call(self):
+        greenargs = self.get_green_varargs()
+        redargs = self.get_red_varargs()
+        bytecodenum = self.load_2byte()
+        targetbytecode = self.frame.bytecode.called_bytecodes[bytecodenum]
+        self.run(self.jitstate, targetbytecode, greenargs, redargs,
+                 start_bytecode_loop=False)
+        # this frame will be resumed later in the next bytecode, which is
+        # yellow_after_direct_call
+
+    def opimpl_yellow_after_direct_call(self):
+        newjitstate = rtimeshift.collect_split(
+            self.jitstate, self.frame.pc,
+            self.frame.local_green)
+        assert newjitstate is self.jitstate
+
+    def opimpl_yellow_retrieve_result(self):
+        # XXX all this jitstate.greens business is a bit messy
+        self.green_result(self.jitstate.greens[0])
+
+
     # ____________________________________________________________
     # construction-time interface
 
@@ -315,6 +347,7 @@
         return self.raise_analyzer.analyze(op)
 
     def make_bytecode(self, graph, is_portal=True):
+        remove_same_as(graph)
         if is_portal:
             self.all_graphs[graph] = JitCode.__new__(JitCode)
         self.seen_blocks = {}
@@ -402,11 +435,11 @@
             returnvar, = block.inputargs
             color = self.varcolor(returnvar)
             if color == "red":
-                index = self.serialize_oparg(color, returnvar)
                 self.emit("red_return")
-                self.emit(index)
             elif originalconcretetype(returnvar) == lltype.Void:
                 self.emit("gray_return")
+            elif color == "green": # really a yellow call # XXX use graphcolor
+                self.emit("yellow_return")
             else:
                 XXX
         elif len(block.exits) == 1:
@@ -680,6 +713,16 @@
             self.emit(emitted_args)
             self.emit(pos)
             self.register_greenvar(op.result)
+        elif kind == "yellow":
+            graphindex = self.graph_position(targetgraph)
+            args = targetgraph.getargs()
+            emitted_args = self.args_of_call(op.args[1:], args)
+            self.emit("yellow_direct_call")
+            self.emit(emitted_args)
+            self.emit(graphindex)
+            self.emit("yellow_after_direct_call")
+            self.emit("yellow_retrieve_result")
+            self.register_greenvar(op.result)
         else:
             XXX
 
@@ -785,7 +828,9 @@
         result.append(chr(index & 0xff))
     for arg in args:
         if isinstance(arg, str):
-            emit_2byte(interpreter.find_opcode(arg))
+            opcode = interpreter.find_opcode(arg)
+            assert opcode >= 0, "unknown opcode %s" % (arg, )
+            emit_2byte(opcode)
         elif isinstance(arg, int):
             emit_2byte(arg)
         elif isinstance(arg, label):
@@ -797,6 +842,8 @@
     for i in range(len(result)):
         b = result[i]
         if isinstance(b, tlabel):
+            for j in range(1, 4):
+                assert result[i + j] is None
             index = labelpos[b.name]
             result[i + 0] = chr((index >> 24) & 0xff)
             result[i + 1] = chr((index >> 16) & 0xff)

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	Mon Feb  4 02:45:07 2008
@@ -476,7 +476,6 @@
         self.check_insns({})
 
     def test_split_on_green_return(self):
-        py.test.skip("calls are WIP")
         def ll_two(x):
             if x > 0:
                 return 17

Modified: pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py
==============================================================================
--- pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py	(original)
+++ pypy/branch/jit-refactoring/pypy/jit/rainbow/test/test_serializegraph.py	Mon Feb  4 02:45:07 2008
@@ -61,7 +61,7 @@
                                         "red_int_add", 0, 1,
                                         "make_new_redvars", 1, 2,
                                         "make_new_greenvars", 0,
-                                        "red_return", 0)
+                                        "red_return")
         assert len(jitcode.constants) == 0
         assert len(jitcode.typekinds) == 0
         assert jitcode.is_portal
@@ -76,7 +76,7 @@
                                         "red_int_add", 0, 1,
                                         "make_new_redvars", 1, 2,
                                         "make_new_greenvars", 0,
-                                        "red_return", 0)
+                                        "red_return")
         assert len(jitcode.constants) == 1
         assert len(jitcode.typekinds) == 1
         assert len(jitcode.redboxclasses) == 1
@@ -97,7 +97,7 @@
                             "make_new_redvars", 1, 1,
                             "make_new_greenvars", 0,
                             label("return"),
-                            "red_return", 0,
+                            "red_return",
                             label("true"),
                             "make_new_redvars", 1, 0,
                             "make_new_greenvars", 0,
@@ -127,7 +127,7 @@
                             "make_new_redvars", 1, 2,
                             "make_new_greenvars", 0,
                             label("return"),
-                            "red_return", 0,
+                            "red_return",
                             label("true"),
                             "make_new_redvars", 2, 0, 1,
                             "make_new_greenvars", 0,
@@ -165,7 +165,7 @@
                             "red_int_add", 1, 0,
                             "make_new_redvars", 1, 2,
                             "make_new_greenvars", 0,
-                            "red_return", 0,
+                            "red_return",
                             label("add"),
                             "make_new_redvars", 2, 1, 2,
                             "make_new_greenvars", 0,
@@ -198,7 +198,7 @@
                             "red_goto_iftrue", 2, tlabel("body"),
                             "make_new_redvars", 1, 0,
                             "make_new_greenvars", 0,
-                            "red_return", 0,
+                            "red_return",
                             label("body"),
                             "make_new_redvars", 2, 0, 1,
                             "make_new_greenvars", 0,
@@ -223,7 +223,7 @@
                                         "red_int_mul", 1, 2,
                                         "make_new_redvars", 1, 3,
                                         "make_new_greenvars", 0,
-                                        "red_return", 0)
+                                        "red_return")
         assert jitcode.is_portal
         assert len(jitcode.called_bytecodes) == 1
         called_jitcode = jitcode.called_bytecodes[0]
@@ -232,7 +232,7 @@
                                                "red_int_add", 0, 1,
                                                "make_new_redvars", 1, 2,
                                                "make_new_greenvars", 0,
-                                               "red_return", 0)
+                                               "red_return")
         assert not called_jitcode.is_portal
         assert len(called_jitcode.called_bytecodes) == 0
 
@@ -250,11 +250,48 @@
                                         "make_redbox", 1, 0,
                                         "make_new_redvars", 1, 0,
                                         "make_new_greenvars", 0,
-                                        "red_return", 0)
+                                        "red_return")
         assert jitcode.is_portal
         assert len(jitcode.called_bytecodes) == 0
         assert len(jitcode.nonrainbow_functions) == 1
 
+    def test_yellow_call(self):
+        def ll_two(x):
+            if x > 0:
+                return 17
+            else:
+                return 22
+        def ll_function(x):
+            n = ll_two(x)
+            return hint(n+1, variable=True)
+        writer, jitcode = self.serialize(ll_function, [int])
+        assert jitcode.code == assemble(writer.interpreter,
+                                        "yellow_direct_call", 0, 1, 0, 0,
+                                        "yellow_after_direct_call",
+                                        "yellow_retrieve_result",
+                                        "green_int_add", 0, -1,
+                                        "make_redbox", 1, 0,
+                                        "make_new_redvars", 1, 1,
+                                        "make_new_greenvars", 0,
+                                        "red_return")
+        assert jitcode.is_portal
+        assert len(jitcode.called_bytecodes) == 1
+        called_jitcode = jitcode.called_bytecodes[0]
+        assert called_jitcode.code == assemble(writer.interpreter,
+                                               "make_redbox", -1, 0,
+                                               "red_int_gt", 0, 1,
+                                               "red_goto_iftrue", 2, tlabel("true"),
+                                               "make_new_redvars", 0,
+                                               "make_new_greenvars", 1, -2,
+                                               label("return"),
+                                               "yellow_return",
+                                               label("true"),
+                                               "make_new_redvars", 0,
+                                               "make_new_greenvars", 1, -3,
+                                               "goto", tlabel("return")
+                                               )
+        assert not called_jitcode.is_portal
+        assert len(called_jitcode.called_bytecodes) == 0
 
 class TestLLType(AbstractSerializationTest):
     type_system = "lltype"

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	Mon Feb  4 02:45:07 2008
@@ -527,7 +527,7 @@
     assert None not in redboxes
     jitstate.frame.local_boxes = redboxes
 
-def save_greens(jitstate, *greens_gv):
+def save_greens(jitstate, greens_gv):
     jitstate.greens = list(greens_gv)
 
 def getlocalbox(jitstate, i):



More information about the Pypy-commit mailing list