[pypy-commit] pypy unroll-if-alt: switch to using the trampoline approach suggested by carl, rather than duplicating a function.

alex_gaynor noreply at buildbot.pypy.org
Tue Sep 20 03:33:44 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: unroll-if-alt
Changeset: r47360:fb2bee32edfb
Date: 2011-09-19 21:33 -0400
http://bitbucket.org/pypy/pypy/changeset/fb2bee32edfb/

Log:	switch to using the trampoline approach suggested by carl, rather
	than duplicating a function.

diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -2947,9 +2947,9 @@
             a = [0, 1, 2, 3, 4]
             while i < n:
                 myjitdriver.jit_merge_point(sa=sa, n=n, a=a, i=i)
-                if i < n/2:
+                if i < n / 2:
                     sa += a[4]
-                elif i == n/2:
+                elif i == n / 2:
                     a.pop()
                 i += 1
         res = self.meta_interp(f, [32])
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -116,33 +116,36 @@
     predicate(*args) returns True
     """
     def inner(func):
-        func_unroll = unroll_safe(func_with_new_name(func, func.__name__ + "_unroll"))
-        # Remove the oopspec, it prevents inlining, which is kinda the whole
-        # point of this rigamaroll.
-        if hasattr(func_unroll, "oopspec"):
-            del func_unroll.oopspec
-        func = dont_look_inside(func)
+        func = unroll_safe(func)
         # When we return the new function, it might be specialized in some
         # way. We "propogate" this specialization by using
         # specialize:call_location on relevant functions.
-        for thing in [func, func_unroll, predicate]:
+        for thing in [func, predicate]:
             thing._annspecialcase_ = "specialize:call_location"
 
         args = _get_args(func)
         d = {
+            "dont_look_inside": dont_look_inside,
             "predicate": predicate,
             "func": func,
-            "func_unroll": func_unroll,
         }
         exec py.code.Source("""
+            @dont_look_inside
+            def trampoline(%(arguments)s):
+                return func(%(arguments)s)
+            if hasattr(func, "oopspec"):
+                # XXX: This seems like it should be here, but it causes errors.
+                # trampoline.oopspec = func.oopspec
+                del func.oopspec
+            trampoline.__name__ = func.__name__ + "_trampoline"
+
             def f(%(arguments)s):
                 if predicate(%(arguments)s):
-                    return func_unroll(%(arguments)s)
+                    return func(%(arguments)s)
                 else:
-                    return func(%(arguments)s)
+                    return trampoline(%(arguments)s)
+            f.__name__ = func.__name__ + "_look_inside_iff"
         """ % {"arguments": ", ".join(args)}).compile() in d
-
-        d["f"].func_name = func.func_name + "_look_inside_iff"
         return d["f"]
     return inner
 


More information about the pypy-commit mailing list