[pypy-svn] r41129 - in pypy/dist/pypy: interpreter module/pypyjit objspace/std

pedronis at codespeak.net pedronis at codespeak.net
Thu Mar 22 23:22:34 CET 2007


Author: pedronis
Date: Thu Mar 22 23:22:33 2007
New Revision: 41129

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/callmethod.py
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/pyframe.py
   pypy/dist/pypy/interpreter/pyopcode.py
   pypy/dist/pypy/module/pypyjit/portal.py
   pypy/dist/pypy/objspace/std/objspace.py
Log:
(arigo, pedronis)

let's the jit see more of the call code.



Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Thu Mar 22 23:22:33 2007
@@ -3,6 +3,7 @@
 from pypy.interpreter.argument import Arguments, ArgumentsFromValuestack
 from pypy.interpreter.pycompiler import CPythonCompiler, PythonAstCompiler
 from pypy.interpreter.miscutils import ThreadLocals
+from pypy.rlib.objectmodel import hint
 from pypy.tool.cache import Cache
 from pypy.tool.uid import HUGEVAL_BYTES
 import os, sys
@@ -619,6 +620,7 @@
     def call_valuestack(self, w_func, nargs, frame):
         # XXX start of hack for performance
         from pypy.interpreter.function import Function, Method
+        hint(w_func.__class__, promote=True)
         if isinstance(w_func, Method):
             w_inst = w_func.w_instance
             if w_inst is not None:
@@ -634,11 +636,12 @@
             return w_func.funccall_valuestack(nargs, frame)
         # XXX end of hack for performance
 
-        args = ArgumentsFromValuestack(self, frame, nargs)
+        args = frame.make_arguments(nargs)
         try:
             return self.call_args(w_func, args)
         finally:
-            args.frame = None
+            if isinstance(args, ArgumentsFromValuestack):
+                args.frame = None
 
     def call_method(self, w_obj, methname, *arg_w):
         w_meth = self.getattr(w_obj, self.wrap(methname))

Modified: pypy/dist/pypy/interpreter/callmethod.py
==============================================================================
--- pypy/dist/pypy/interpreter/callmethod.py	(original)
+++ pypy/dist/pypy/interpreter/callmethod.py	Thu Mar 22 23:22:33 2007
@@ -61,19 +61,10 @@
     def CALL_METHOD(f, nargs, *ignored):
         # 'nargs' is the argument count excluding the implicit 'self'
         w_self = f.peekvalue(nargs)
-        if we_are_jitted():
-            if w_self is None:
-                args = f.popvalues(nargs)
-                f.popvalue() # w_self
-            else:
-                args = f.popvalues(nargs + 1)
-            w_callable = f.popvalue()
-            w_result = f.space.call_args(w_callable, Arguments(f.space, args))
-        else:
-            w_callable = f.peekvalue(nargs + 1)
-            n = nargs + (w_self is not None)
-            try:
-                w_result = f.space.call_valuestack(w_callable, n, f)
-            finally:
-                f.dropvalues(nargs + 2)
+        w_callable = f.peekvalue(nargs + 1)
+        n = nargs + (w_self is not None)
+        try:
+            w_result = f.space.call_valuestack(w_callable, n, f)
+        finally:
+            f.dropvalues(nargs + 2)
         f.pushvalue(w_result)

Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Thu Mar 22 23:22:33 2007
@@ -49,78 +49,81 @@
             if w_res is not None:
                 return w_res
         elif len(args_w) == 2:
-            w_res = code.fastcall_2(self.space, self, args_w[0],
-                                           args_w[1])
+            w_res = code.fastcall_2(self.space, self, args_w[0], args_w[1])
             if w_res is not None:
                 return w_res
         elif len(args_w) == 3:
             w_res = code.fastcall_3(self.space, self, args_w[0],
-                                           args_w[1], args_w[2])
+                                    args_w[1], args_w[2])
             if w_res is not None:
                 return w_res
         elif len(args_w) == 4:
             w_res = code.fastcall_4(self.space, self, args_w[0],
-                                           args_w[1], args_w[2], args_w[3])
+                                    args_w[1], args_w[2], args_w[3])
             if w_res is not None:
                 return w_res
         return self.call_args(Arguments(self.space, list(args_w)))
 
     def funccall_valuestack(self, nargs, frame): # speed hack
+        code = self.getcode() # hook for the jit
         if nargs == 0:
-            w_res = self.code.fastcall_0(self.space, self)
+            w_res = code.fastcall_0(self.space, self)
             if w_res is not None:
                 return w_res
         elif nargs == 1:
-            w_res = self.code.fastcall_1(self.space, self, frame.peekvalue(0))
+            w_res = code.fastcall_1(self.space, self, frame.peekvalue(0))
             if w_res is not None:
                 return w_res
         elif nargs == 2:
-            w_res = self.code.fastcall_2(self.space, self, frame.peekvalue(1),
-                                         frame.peekvalue(0))
+            w_res = code.fastcall_2(self.space, self, frame.peekvalue(1),
+                                    frame.peekvalue(0))
             if w_res is not None:
                 return w_res
         elif nargs == 3:
-            w_res = self.code.fastcall_3(self.space, self, frame.peekvalue(2),
-                                         frame.peekvalue(1), frame.peekvalue(0))
+            w_res = code.fastcall_3(self.space, self, frame.peekvalue(2),
+                                    frame.peekvalue(1), frame.peekvalue(0))
             if w_res is not None:
                 return w_res
         elif nargs == 4:
-            w_res = self.code.fastcall_4(self.space, self, frame.peekvalue(3),
-                                         frame.peekvalue(2), frame.peekvalue(1),
-                                         frame.peekvalue(0))
+            w_res = code.fastcall_4(self.space, self, frame.peekvalue(3),
+                                    frame.peekvalue(2), frame.peekvalue(1),
+                                    frame.peekvalue(0))
             if w_res is not None:
                 return w_res
-        args = ArgumentsFromValuestack(self.space, frame, nargs)
+        args = frame.make_arguments(nargs)
         try:
             return self.call_args(args)
         finally:
-            args.frame = None
+            if isinstance(args, ArgumentsFromValuestack):
+                args.frame = None
 
     def funccall_obj_valuestack(self, w_obj, nargs, frame): # speed hack
+        code = self.getcode() # hook for the jit
         if nargs == 0:
-            w_res = self.code.fastcall_1(self.space, self, w_obj)
+            w_res = code.fastcall_1(self.space, self, w_obj)
             if w_res is not None:
                 return w_res
         elif nargs == 1:
-            w_res = self.code.fastcall_2(self.space, self, w_obj, frame.peekvalue(0))
+            w_res = code.fastcall_2(self.space, self, w_obj, frame.peekvalue(0))
             if w_res is not None:
                 return w_res
         elif nargs == 2:
-            w_res = self.code.fastcall_3(self.space, self, w_obj, frame.peekvalue(1),
-                                         frame.peekvalue(0))
+            w_res = code.fastcall_3(self.space, self, w_obj, frame.peekvalue(1),
+                                    frame.peekvalue(0))
             if w_res is not None:
                 return w_res
         elif nargs == 3:
-            w_res = self.code.fastcall_4(self.space, self, w_obj, frame.peekvalue(2),
-                                         frame.peekvalue(1), frame.peekvalue(0))
+            w_res = code.fastcall_4(self.space, self, w_obj, frame.peekvalue(2),
+                                    frame.peekvalue(1), frame.peekvalue(0))
             if w_res is not None:
                 return w_res
-        stkargs = ArgumentsFromValuestack(self.space, frame, nargs)
+        stkargs = frame.make_arguments(nargs)
         args = stkargs.prepend(w_obj)
         try:
             return self.call_args(args)
         finally:
-            stkargs.frame = None
+            if isinstance(stkargs, ArgumentsFromValuestack):
+                stkargs.frame = None
 
     def getdict(self):
         if self.w_func_dict is None:

Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py	(original)
+++ pypy/dist/pypy/interpreter/pyframe.py	Thu Mar 22 23:22:33 2007
@@ -3,10 +3,12 @@
 
 from pypy.tool.pairtype import extendabletype
 from pypy.interpreter import eval, baseobjspace, pycode
+from pypy.interpreter.argument import Arguments, ArgumentsFromValuestack
 from pypy.interpreter.error import OperationError
 from pypy.interpreter import pytraceback
 import opcode
-from pypy.rlib.objectmodel import we_are_translated, instantiate, hint
+from pypy.rlib.objectmodel import we_are_translated, instantiate
+from pypy.rlib.objectmodel import we_are_jitted, hint
 from pypy.rlib import rstack # for resume points
 
 
@@ -149,6 +151,18 @@
             values_w[n] = self.popvalue()
         return values_w
 
+    def peekvalues(self, n):
+        values_w = [None] * n
+        base = self.valuestackdepth - n
+        assert base >= 0
+        while True:
+            n -= 1
+            if n < 0:
+                break
+            hint(n, concrete=True)
+            values_w[n] = self.valuestack_w[base+n]
+        return values_w
+
     def pushrevvalues(self, n, values_w): # n should be len(values_w)
         while True:
             n -= 1
@@ -197,7 +211,12 @@
         self.valuestack_w[:len(items_w)] = items_w
         self.dropvaluesuntil(len(items_w))
 
-
+    def make_arguments(self, nargs):
+        if we_are_jitted():
+            return Arguments(self.space, self.peekvalues(nargs))
+        else:
+            return ArgumentsFromValuestack(self.space, self, nargs)
+            
     def descr__reduce__(self, space):
         from pypy.interpreter.mixedmodule import MixedModule
         from pypy.module._pickle_support import maker # helper fns

Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py	(original)
+++ pypy/dist/pypy/interpreter/pyopcode.py	Thu Mar 22 23:22:33 2007
@@ -822,7 +822,7 @@
         
     def CALL_FUNCTION(f, oparg, *ignored):
         # XXX start of hack for performance
-        if not we_are_jitted() and (oparg >> 8) & 0xff == 0:
+        if (oparg >> 8) & 0xff == 0:
             # Only positional arguments
             nargs = oparg & 0xff
             w_function = f.peekvalue(nargs)

Modified: pypy/dist/pypy/module/pypyjit/portal.py
==============================================================================
--- pypy/dist/pypy/module/pypyjit/portal.py	(original)
+++ pypy/dist/pypy/module/pypyjit/portal.py	Thu Mar 22 23:22:33 2007
@@ -191,7 +191,15 @@
             pypy.objspace.std.Space.is_true)
     seepath(pypy.interpreter.pyframe.PyFrame.JUMP_IF_FALSE,
             pypy.objspace.std.Space.is_true)
-    
+
+    #
+    seepath(pypy.interpreter.pyframe.PyFrame.CALL_FUNCTION,
+            pypy.interpreter.function.Function.funccall_valuestack)
+    seepath(pypy.interpreter.pyframe.PyFrame.CALL_FUNCTION,
+            pypy.interpreter.function.Function.funccall_obj_valuestack)
+
+
+    import pdb; pdb.set_trace()
     return result_graphs
 
 

Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Thu Mar 22 23:22:33 2007
@@ -110,16 +110,12 @@
                                          f.space.wrap(message))
                 nargs = oparg & 0xff
                 w_function = w_value
-                if we_are_jitted():
-                    args = Arguments(f.space, f.popvalues(nargs))
-                    w_result = f.space.call_args(w_function, args)
-                else:
-                    try:
-                        w_result = f.space.call_valuestack(w_function, nargs, f)
-                        # XXX XXX fix the problem of resume points!
-                        #rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result)
-                    finally:
-                        f.dropvalues(nargs)
+                try:
+                    w_result = f.space.call_valuestack(w_function, nargs, f)
+                    # XXX XXX fix the problem of resume points!
+                    #rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result)
+                finally:
+                    f.dropvalues(nargs)
                 f.pushvalue(w_result)
 
         self.FrameClass = StdObjSpaceFrame



More information about the Pypy-commit mailing list