Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: unroll-if-alt
Changeset: r46219:524483d98407
Date: 2011-08-02 17:17 -0700
http://bitbucket.org/pypy/pypy/changeset/524483d98407/

Log:    a) Renamed @unroll_if to @look_inside_iff at carl's request b)
        Unroll Argument.unpack if one should. c) Leave a comment about a
        small level mess with keyword argumengs and the decorator

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -125,6 +125,7 @@
 
     ###  Manipulation  ###
 
+    @jit.look_inside_iff(lambda self: not self._dont_jit)
     def unpack(self): # slowish
         "Return a ([w1,w2...], {'kw':w3...}) pair."
         kwds_w = {}
@@ -245,6 +246,8 @@
 
     ###  Parsing for function calls  ###
 
+    # XXX: this should be @jit.look_inside_iff, but we need key word arguments,
+    # and it doesn't support them for now.
     def _match_signature(self, w_firstarg, scope_w, signature, defaults_w=None,
                          blindargs=0):
         """Parse args and kwargs according to the signature of a code object,
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
@@ -12,7 +12,7 @@
 from pypy.jit.metainterp.warmstate import set_future_value
 from pypy.rlib.jit import (JitDriver, we_are_jitted, hint, dont_look_inside,
     loop_invariant, elidable, promote, jit_debug, assert_green,
-    AssertGreenFailed, unroll_safe, current_trace_length, unroll_if, 
isconstant)
+    AssertGreenFailed, unroll_safe, current_trace_length, look_inside_iff, 
isconstant)
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.ootypesystem import ootype
@@ -2683,8 +2683,8 @@
 
         self.meta_interp(f, [10], repeat=3)
 
-    def test_unroll_if_const(self):
-        @unroll_if(lambda arg: isconstant(arg))
+    def test_look_inside_iff_const(self):
+        @look_inside_iff(lambda arg: isconstant(arg))
         def f(arg):
             s = 0
             while arg > 0:
@@ -2728,7 +2728,7 @@
             'int_gt': 1, 'int_sub': 1, 'strlen': 1, 'jump': 1,
         })
 
-    def test_unroll_if_const_getarrayitem_gc_pure(self):
+    def test_look_inside_iff_const_getarrayitem_gc_pure(self):
         driver = JitDriver(greens=['unroll'], reds=['s', 'n'])
 
         class A(object):
@@ -2736,7 +2736,7 @@
             def __init__(self, x):
                 self.x = [x]
 
-        @unroll_if(lambda x: isconstant(x))
+        @look_inside_iff(lambda x: isconstant(x))
         def f(x):
             i = 0
             for c in x:
diff --git a/pypy/objspace/std/formatting.py b/pypy/objspace/std/formatting.py
--- a/pypy/objspace/std/formatting.py
+++ b/pypy/objspace/std/formatting.py
@@ -285,7 +285,7 @@
                 c = self.peekchr()
             return result
 
-        @jit.unroll_if(lambda self: jit.isconstant(self.fmt))
+        @jit.look_inside_iff(lambda self: jit.isconstant(self.fmt))
         def format(self):
             lgt = len(self.fmt) + 4 * len(self.values_w) + 10
             if do_unicode:
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -132,7 +132,7 @@
             cache[selector] = attr
         return attr
 
-    @jit.unroll_if(lambda self, obj, selector, w_value:
+    @jit.look_inside_iff(lambda self, obj, selector, w_value:
             jit.isconstant(self) and
             jit.isconstant(selector[0]) and
             jit.isconstant(selector[1]))
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -108,10 +108,15 @@
     warnings.warn("purefunction_promote is deprecated, use elidable_promote 
instead", DeprecationWarning)
     return elidable_promote(*args, **kwargs)
 
-def unroll_if(predicate):
+def look_inside_iff(predicate):
+    """
+    look inside (including unrolling loops) the target function, if and only if
+    predicate(*args) returns True
+    """
     def inner(func):
         func_unroll = unroll_safe(func_with_new_name(func, func.__name__ + 
"_unroll"))
-        for thing in func, func_unroll, predicate:
+        func = dont_look_inside(func)
+        for thing in [func, func_unroll, predicate]:
             thing._annspecialcase_ = "specialize:call_location"
 
         def f(*args):
@@ -120,7 +125,7 @@
             else:
                 return func(*args)
 
-        f.func_name = func.func_name + "_unroll_if"
+        f.func_name = func.func_name + "_look_inside_iff"
         return f
     return inner
 
@@ -136,7 +141,7 @@
     """
     While tracing, returns whether or not the value is currently known to be
     constant. This is not perfect, values can become constant later. Mostly for
-    use with @unroll_if.
+    use with @look_inside_iff.
     """
     # I hate the annotator so much.
     if NonConstant(False):
diff --git a/pypy/rlib/rstruct/formatiterator.py 
b/pypy/rlib/rstruct/formatiterator.py
--- a/pypy/rlib/rstruct/formatiterator.py
+++ b/pypy/rlib/rstruct/formatiterator.py
@@ -16,7 +16,7 @@
     _mixin_ = True
     _operate_is_specialized_ = False
 
-    @jit.unroll_if(lambda self, fmt: jit.isconstant(fmt))
+    @jit.look_inside_iff(lambda self, fmt: jit.isconstant(fmt))
     def interpret(self, fmt):
         # decode the byte order, size and alignment based on the 1st char
         table = unroll_native_fmtdescs
diff --git a/pypy/rpython/lltypesystem/rbuilder.py 
b/pypy/rpython/lltypesystem/rbuilder.py
--- a/pypy/rpython/lltypesystem/rbuilder.py
+++ b/pypy/rpython/lltypesystem/rbuilder.py
@@ -92,7 +92,7 @@
         ll_builder.used = needed + used
 
     @staticmethod
-    @jit.unroll_if(lambda ll_builder, char, times: jit.isconstant(times) and 
times <= 4)
+    @jit.look_inside_iff(lambda ll_builder, char, times: jit.isconstant(times) 
and times <= 4)
     def ll_append_multiple_char(ll_builder, char, times):
         used = ll_builder.used
         if times + used > ll_builder.allocated:
diff --git a/pypy/rpython/lltypesystem/rstr.py 
b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -680,7 +680,7 @@
             return -1
         return count
 
-    @jit.unroll_if(lambda length, items: jit.isconstant(length) and length <= 
2)
+    @jit.look_inside_iff(lambda length, items: jit.isconstant(length) and 
length <= 2)
     @enforceargs(int, None)
     def ll_join_strs(length, items):
         # Special case for length 1 items, helps both the JIT and other code
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to