[pypy-svn] r68453 - in pypy/branch/prevent-silly-unrolling/pypy: interpreter jit/metainterp module/__builtin__ module/pypyjit objspace/std

pedronis at codespeak.net pedronis at codespeak.net
Wed Oct 14 18:29:41 CEST 2009


Author: pedronis
Date: Wed Oct 14 18:29:40 2009
New Revision: 68453

Modified:
   pypy/branch/prevent-silly-unrolling/pypy/interpreter/argument.py
   pypy/branch/prevent-silly-unrolling/pypy/interpreter/executioncontext.py
   pypy/branch/prevent-silly-unrolling/pypy/interpreter/function.py
   pypy/branch/prevent-silly-unrolling/pypy/interpreter/nestedscope.py
   pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyframe.py
   pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyopcode.py
   pypy/branch/prevent-silly-unrolling/pypy/jit/metainterp/policy.py
   pypy/branch/prevent-silly-unrolling/pypy/module/__builtin__/abstractinst.py
   pypy/branch/prevent-silly-unrolling/pypy/module/pypyjit/policy.py
   pypy/branch/prevent-silly-unrolling/pypy/objspace/std/sharingdict.py
   pypy/branch/prevent-silly-unrolling/pypy/objspace/std/stdtypedef.py
Log:
(pedronis, cfbolz): sprinkle unroll_safe in strategic places. clean up the
policy of the Python interpreter


Modified: pypy/branch/prevent-silly-unrolling/pypy/interpreter/argument.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/interpreter/argument.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/interpreter/argument.py	Wed Oct 14 18:29:40 2009
@@ -4,7 +4,7 @@
 
 from pypy.interpreter.error import OperationError
 from pypy.rlib.debug import make_sure_not_resized
-from pypy.rlib.jit import purefunction
+from pypy.rlib.jit import purefunction, unroll_safe
 
 
 class Signature(object):
@@ -99,7 +99,8 @@
             make_sure_not_resized(self.keywords_w)
 
         make_sure_not_resized(self.arguments_w)
-        self._combine_wrapped(w_stararg, w_starstararg)
+        if w_stararg is not None or w_starstararg is not None:
+            self._combine_wrapped(w_stararg, w_starstararg)
         
     def __repr__(self):
         """ NOT_RPYTHON """
@@ -187,6 +188,7 @@
         
     ###  Parsing for function calls  ###
 
+    @unroll_safe # XXX not true always, but for now
     def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=[],
                          blindargs=0):
         """Parse args and kwargs according to the signature of a code object,

Modified: pypy/branch/prevent-silly-unrolling/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/interpreter/executioncontext.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/interpreter/executioncontext.py	Wed Oct 14 18:29:40 2009
@@ -34,12 +34,12 @@
             frame = frame.f_back()
         return frame
 
+    @staticmethod
     def getnextframe_nohidden(frame):
         frame = frame.f_back()
         while frame and frame.hide():
             frame = frame.f_back()
         return frame
-    getnextframe_nohidden = staticmethod(getnextframe_nohidden)
 
     def enter(self, frame):
         if self.framestackdepth > self.space.sys.recursionlimit:
@@ -60,6 +60,7 @@
     # the methods below are used for chaining frames in JIT-friendly way
     # part of that stuff is obscure
 
+    @jit.unroll_safe
     def gettopframe(self):
         frame = self.some_frame
         if frame is not None:
@@ -157,6 +158,7 @@
         ec.some_frame = frame
 
     @staticmethod
+    @jit.unroll_safe
     def _extract_back_from_frame(frame):
         back_some = frame.f_back_some
         if frame.f_back_forced:

Modified: pypy/branch/prevent-silly-unrolling/pypy/interpreter/function.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/interpreter/function.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/interpreter/function.py	Wed Oct 14 18:29:40 2009
@@ -11,7 +11,7 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.eval import Code
 from pypy.interpreter.argument import Arguments
-from pypy.rlib.jit import hint
+from pypy.rlib import jit
 from pypy.rlib.debug import make_sure_not_resized
 
 funccallunrolling = unrolling_iterable(range(4))
@@ -48,7 +48,7 @@
         return self.getcode().funcrun_obj(self, w_obj, args)
 
     def getcode(self):
-        return hint(self.code, promote=True)
+        return jit.hint(self.code, promote=True)
     
     def funccall(self, *args_w): # speed hack
         from pypy.interpreter import gateway
@@ -135,6 +135,7 @@
         args = frame.make_arguments(nargs)
         return self.call_args(args)
 
+    @jit.unroll_safe
     def _flat_pycall(self, code, nargs, frame):
         # code is a PyCode
         new_frame = self.space.createframe(code, self.w_func_globals,
@@ -145,6 +146,7 @@
             
         return new_frame.run()                        
 
+    @jit.unroll_safe
     def _flat_pycall_defaults(self, code, nargs, frame, defs_to_load):
         # code is a PyCode
         new_frame = self.space.createframe(code, self.w_func_globals,

Modified: pypy/branch/prevent-silly-unrolling/pypy/interpreter/nestedscope.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/interpreter/nestedscope.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/interpreter/nestedscope.py	Wed Oct 14 18:29:40 2009
@@ -2,6 +2,7 @@
 from pypy.interpreter import function, pycode, pyframe
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.mixedmodule import MixedModule
+from pypy.rlib import jit
 from pypy.tool.uid import uid
 
 class Cell(Wrappable):
@@ -149,6 +150,7 @@
             else:
                 cell.set(w_value)
 
+    @jit.unroll_safe
     def init_cells(self):
         if self.cells is None:
             return

Modified: pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyframe.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyframe.py	Wed Oct 14 18:29:40 2009
@@ -188,6 +188,7 @@
     # we need two popvalues that return different data types:
     # one in case we want list another in case of tuple
     def _new_popvalues():
+        @jit.unroll_safe
         def popvalues(self, n):
             values_w = [None] * n
             while True:
@@ -201,6 +202,7 @@
     popvalues_mutable = _new_popvalues()
     del _new_popvalues
 
+    @jit.unroll_safe
     def peekvalues(self, n):
         values_w = [None] * n
         base = self.valuestackdepth - n
@@ -212,6 +214,7 @@
             values_w[n] = self.valuestack_w[base+n]
         return values_w
 
+    @jit.unroll_safe
     def dropvalues(self, n):
         n = hint(n, promote=True)
         finaldepth = self.valuestackdepth - n
@@ -223,6 +226,7 @@
             self.valuestack_w[finaldepth+n] = None
         self.valuestackdepth = finaldepth
 
+    @jit.unroll_safe
     def pushrevvalues(self, n, values_w): # n should be len(values_w)
         make_sure_not_resized(values_w)
         while True:
@@ -231,6 +235,7 @@
                 break
             self.pushvalue(values_w[n])
 
+    @jit.unroll_safe
     def dupvalues(self, n):
         delta = n-1
         while True:
@@ -252,6 +257,7 @@
         assert index >= 0, "settop past the bottom of the stack"
         self.valuestack_w[index] = w_object
 
+    @jit.unroll_safe
     def dropvaluesuntil(self, finaldepth):
         depth = self.valuestackdepth - 1
         finaldepth = hint(finaldepth, promote=True)

Modified: pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyopcode.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/interpreter/pyopcode.py	Wed Oct 14 18:29:40 2009
@@ -12,7 +12,7 @@
 from pypy.interpreter.pycode import PyCode
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib.objectmodel import we_are_translated
-from pypy.rlib.jit import hint, we_are_jitted
+from pypy.rlib import jit
 from pypy.rlib.rarithmetic import r_uint, intmask
 from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
 from pypy.tool.stdlib_opcode import unrolling_opcode_descs
@@ -130,7 +130,7 @@
 
     def handle_operation_error(self, ec, operr, attach_tb=True):
         if attach_tb:
-            if not we_are_jitted():
+            if not jit.we_are_jitted():
                 # xxx this is a hack.  It allows bytecode_trace() to
                 # call a signal handler which raises, and catch the
                 # raised exception immediately.  See test_alarm_raise in
@@ -153,7 +153,7 @@
                     operr = e
             pytraceback.record_application_traceback(
                 self.space, operr, self, self.last_instr)
-            if not we_are_jitted():
+            if not jit.we_are_jitted():
                 ec.exception_trace(self, operr)
 
         block = self.unrollstack(SApplicationException.kind)
@@ -175,7 +175,7 @@
         space = self.space
         while True:
             self.last_instr = intmask(next_instr)
-            if not we_are_jitted():
+            if not jit.we_are_jitted():
                 ec.bytecode_trace(self)
                 next_instr = r_uint(self.last_instr)
             opcode = ord(co_code[next_instr])
@@ -268,12 +268,13 @@
                 if res is not None:
                     next_instr = res
 
-            if we_are_jitted():
+            if jit.we_are_jitted():
                 return next_instr
 
+    @jit.unroll_safe
     def unrollstack(self, unroller_kind):
         n = self.blockcount
-        n = hint(n, promote=True)
+        n = jit.hint(n, promote=True)
         while n > 0:
             block = self.pop_block()
             n -= 1
@@ -889,6 +890,7 @@
                                   f.space.w_None,
                                   f.space.w_None)
                       
+    @jit.unroll_safe
     def call_function(f, oparg, w_star=None, w_starstar=None):
         from pypy.rlib import rstack # for resume points
         from pypy.interpreter.function import is_builtin_code
@@ -914,7 +916,7 @@
         arguments = f.popvalues(n_arguments)
         args = f.argument_factory(arguments, keywords, keywords_w, w_star, w_starstar)
         w_function  = f.popvalue()
-        if we_are_jitted():
+        if jit.we_are_jitted():
             w_result = f.space.call_args(w_function, args)
         else:
             if f.is_being_profiled and is_builtin_code(w_function):

Modified: pypy/branch/prevent-silly-unrolling/pypy/jit/metainterp/policy.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/jit/metainterp/policy.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/jit/metainterp/policy.py	Wed Oct 14 18:29:40 2009
@@ -43,11 +43,10 @@
             contains_loop = contains_loop and not getattr(
                     func, '_jit_unroll_safe_', False)
 
-        res = (see_function and not contains_loop and
-               not unsupported)
-        if not res and see_function and not unsupported:
+        res = see_function and not unsupported
+        if res and contains_loop:
             self.unsafe_loopy_graphs.add(graph)
-        return res
+        return res and not contains_loop
 
     def graphs_from(self, op, rtyper, supports_floats):
         if op.opname == 'direct_call':

Modified: pypy/branch/prevent-silly-unrolling/pypy/module/__builtin__/abstractinst.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/module/__builtin__/abstractinst.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/module/__builtin__/abstractinst.py	Wed Oct 14 18:29:40 2009
@@ -115,6 +115,7 @@
     return False
 
 
+ at jit.unroll_safe
 def abstract_issubclass_w(space, w_derived, w_klass_or_tuple):
     """Implementation for the full 'issubclass(derived, klass_or_tuple)'."""
 
@@ -138,6 +139,7 @@
     # from here on, we are sure that w_derived is a class-like object
 
     # -- case (class-like-object, tuple-of-classes)
+    # XXX it might be risky that the JIT sees this
     if space.is_true(space.isinstance(w_klass_or_tuple, space.w_tuple)):
         for w_klass in space.viewiterable(w_klass_or_tuple):
             if abstract_issubclass_w(space, w_derived, w_klass):

Modified: pypy/branch/prevent-silly-unrolling/pypy/module/pypyjit/policy.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/module/pypyjit/policy.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/module/pypyjit/policy.py	Wed Oct 14 18:29:40 2009
@@ -2,21 +2,19 @@
 
 class PyPyJitPolicy(JitPolicy):
 
+    def look_inside_pypy_module(self, modname):
+        if mod.startswith('pypy.module.__builtin__'):
+            if mod.endswith('operation') or mod.endswith('abstractinst'):
+                return True
+
+        modname, _ = modname.split('.', 1)
+        if modname in ['pypyjit', 'signal', 'micronumpy', 'math']:
+            return True
+        return False
+
     def look_inside_function(self, func):
         mod = func.__module__ or '?'
-        if (func.__name__.startswith('_mm_') or
-            func.__name__.startswith('__mm_')):
-            # multimethods
-            return True
-        if '_mth_mm_' in func.__name__:    # e.g. str_mth_mm_join_xxx
-            return True
         
-        # weakref support
-        if mod == 'pypy.objspace.std.typeobject':
-            if func.__name__ in ['get_subclasses', 'add_subclass',
-                                 'remove_subclass']:
-                return False
-
         if mod.startswith('pypy.objspace.'):
             # gc_id operation
             if func.__name__ == 'id__ANY':
@@ -34,16 +32,11 @@
         if mod.startswith('pypy.interpreter.pyparser.'):
             return False
         if mod.startswith('pypy.module.'):
-            if mod.startswith('pypy.module.__builtin__'):
-                if mod.endswith('operation') or mod.endswith('abstractinst'):
-                    return True
-
-            modname = mod.split('.')[2]
-            if modname in ['pypyjit', 'signal', 'micronumpy', 'math']:
-                return True
-            return False
+            modname = mod[len('pypy.'):]
+            if not self.look_inside_pypy_module(modname):
+                return False
             
-        if mod.startswith('pypy.translator.'):
+        if mod.startswith('pypy.translator.'): # XXX wtf?
             return False
         # string builder interface
         if mod == 'pypy.rpython.lltypesystem.rbuilder':
@@ -51,12 +44,5 @@
         # rweakvaluedict implementation
         if mod == 'pypy.rlib.rweakrefimpl':
             return False
-        #if (mod == 'pypy.rpython.rlist' or
-        #    mod == 'pypy.rpython.lltypesystem.rdict' or
-        #    mod == 'pypy.rpython.lltypesystem.rlist'):
-        #    # non oopspeced list or dict operations are helpers
-        #    return False
-        #if func.__name__ == 'll_update':
-        #    return False
         
         return super(PyPyJitPolicy, self).look_inside_function(func)

Modified: pypy/branch/prevent-silly-unrolling/pypy/objspace/std/sharingdict.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/objspace/std/sharingdict.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/objspace/std/sharingdict.py	Wed Oct 14 18:29:40 2009
@@ -1,7 +1,7 @@
 from pypy.objspace.std.dictmultiobject import DictImplementation, StrDictImplementation
 from pypy.objspace.std.dictmultiobject import IteratorImplementation
 from pypy.objspace.std.dictmultiobject import W_DictMultiObject, _is_sane_hash
-from pypy.rlib.jit import purefunction, hint, we_are_jitted
+from pypy.rlib.jit import purefunction, hint, we_are_jitted, unroll_safe
 from pypy.rlib.rweakref import RWeakValueDictionary
 
 NUM_DIGITS = 4
@@ -103,6 +103,7 @@
         else:
             return self._as_rdict().setitem(w_key, w_value)
 
+    @unroll_safe
     def setitem_str(self, w_key, w_value, shadows_type=True):
         key = self.space.str_w(w_key)
         i = self.structure.lookup_position(key)

Modified: pypy/branch/prevent-silly-unrolling/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/branch/prevent-silly-unrolling/pypy/objspace/std/stdtypedef.py	(original)
+++ pypy/branch/prevent-silly-unrolling/pypy/objspace/std/stdtypedef.py	Wed Oct 14 18:29:40 2009
@@ -6,6 +6,7 @@
 from pypy.interpreter.baseobjspace import SpaceCache
 from pypy.objspace.std.model import StdObjSpaceMultiMethod
 from pypy.objspace.std.multimethod import FailedToImplement
+from pypy.rlib import jit
 from pypy.tool.sourcetools import compile2
 
 __all__ = ['StdTypeDef', 'newmethod', 'gateway',
@@ -27,6 +28,7 @@
         "NOT_RPYTHON: initialization-time only."
         self.local_multimethods += hack_out_multimethods(namespace)
 
+ at jit.unroll_safe
 def issubtypedef(a, b):
     from pypy.objspace.std.objecttype import object_typedef
     if b is object_typedef:



More information about the Pypy-commit mailing list