[pypy-commit] pypy unroll-if-alt: Started working on making sure list methods are appeneded on virtual lists, tests failing due to not folding int_add_ovf(0, 1) in the frontend.
alex_gaynor
noreply at buildbot.pypy.org
Mon Sep 19 15:01:34 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: unroll-if-alt
Changeset: r47349:d63620cc570c
Date: 2011-09-19 09:00 -0400
http://bitbucket.org/pypy/pypy/changeset/d63620cc570c/
Log: Started working on making sure list methods are appeneded on virtual
lists, tests failing due to not folding int_add_ovf(0, 1) in the
frontend.
diff --git a/pypy/jit/metainterp/test/test_list.py b/pypy/jit/metainterp/test/test_list.py
--- a/pypy/jit/metainterp/test/test_list.py
+++ b/pypy/jit/metainterp/test/test_list.py
@@ -34,7 +34,7 @@
l = [x + 1]
n -= 1
return l[0]
-
+
res = self.meta_interp(f, [10], listops=True)
assert res == f(10)
self.check_all_virtualized()
@@ -60,7 +60,7 @@
def test_ll_fixed_setitem_fast(self):
jitdriver = JitDriver(greens = [], reds = ['n', 'l'])
-
+
def f(n):
l = [1, 2, 3]
@@ -116,7 +116,7 @@
assert res == f(10)
py.test.skip("'[non-null] * n' gives a residual call so far")
self.check_loops(setarrayitem_gc=0, getarrayitem_gc=0, call=0)
-
+
def test_arraycopy_simpleoptimize(self):
def f():
l = [1, 2, 3, 4]
@@ -208,6 +208,26 @@
assert res == f(15)
self.check_loops(guard_exception=0)
+ def test_virtual_resize(self):
+ jitdriver = JitDriver(greens = [], reds = ['n', 's'])
+ def f(n):
+ s = 0
+ while n > 0:
+ jitdriver.jit_merge_point(n=n, s=s)
+ lst = []
+ lst += [1]
+ n -= len(lst)
+ s += lst[0]
+ lst.pop()
+ lst.append(1)
+ s /= lst.pop()
+ return s
+ res = self.meta_interp(f, [15], listops=True)
+ assert res == f(15)
+ self.check_loops({"int_add": 1, "int_sub": 1, "int_gt": 1,
+ "guard_true": 1, "jump": 1})
+
+
class TestOOtype(ListTests, OOJitMixin):
pass
diff --git a/pypy/jit/metainterp/test/test_slist.py b/pypy/jit/metainterp/test/test_slist.py
--- a/pypy/jit/metainterp/test/test_slist.py
+++ b/pypy/jit/metainterp/test/test_slist.py
@@ -5,7 +5,6 @@
class ListTests(object):
def test_basic_list(self):
- py.test.skip("not yet")
myjitdriver = JitDriver(greens = [], reds = ['n', 'lst'])
def f(n):
lst = []
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -121,14 +121,22 @@
for thing in [func, func_unroll, predicate]:
thing._annspecialcase_ = "specialize:call_location"
- def f(*args):
- if predicate(*args):
- return func_unroll(*args)
- else:
- return func(*args)
+ args = _get_args(func)
+ d = {
+ "predicate": predicate,
+ "func": func,
+ "func_unroll": func_unroll,
+ }
+ exec py.code.Source("""
+ def f(%(arguments)s):
+ if predicate(%(arguments)s):
+ return func_unroll(%(arguments)s)
+ else:
+ return func(%(arguments)s)
+ """ % {"arguments": ", ".join(args)}).compile() in d
- f.func_name = func.func_name + "_look_inside_iff"
- return f
+ d["f"].func_name = func.func_name + "_look_inside_iff"
+ return d["f"]
return inner
def oopspec(spec):
diff --git a/pypy/rpython/lltypesystem/rlist.py b/pypy/rpython/lltypesystem/rlist.py
--- a/pypy/rpython/lltypesystem/rlist.py
+++ b/pypy/rpython/lltypesystem/rlist.py
@@ -9,7 +9,7 @@
GcStruct, Void, Signed, malloc, typeOf, nullptr, typeMethod
from pypy.rpython.lltypesystem import rstr
from pypy.rlib.debug import ll_assert
-from pypy.rlib import rgc
+from pypy.rlib import rgc, jit
# ____________________________________________________________
#
@@ -225,19 +225,20 @@
else:
_ll_list_resize_really(l, newsize)
+ at jit.look_inside_iff(lambda l, newsize: jit.isconstant(len(l.items)) and jit.isconstant(newsize))
+ at jit.oopspec("list._resize_ge(l, newsize)")
def _ll_list_resize_ge(l, newsize):
if len(l.items) >= newsize:
l.length = newsize
else:
_ll_list_resize_really(l, newsize)
-_ll_list_resize_ge.oopspec = 'list._resize_ge(l, newsize)'
def _ll_list_resize_le(l, newsize):
if newsize >= (len(l.items) >> 1) - 5:
l.length = newsize
else:
_ll_list_resize_really(l, newsize)
-
+_ll_list_resize_le.oopspec = 'list._resize_le(l, newsize)'
def ll_append_noresize(l, newitem):
length = l.length
diff --git a/pypy/rpython/rlist.py b/pypy/rpython/rlist.py
--- a/pypy/rpython/rlist.py
+++ b/pypy/rpython/rlist.py
@@ -116,7 +116,7 @@
v_lst = hop.inputarg(self, 0)
cRESLIST = hop.inputconst(Void, hop.r_result.LIST)
return hop.gendirectcall(ll_copy, cRESLIST, v_lst)
-
+
def rtype_len(self, hop):
v_lst, = hop.inputargs(self)
if hop.args_s[0].listdef.listitem.resized:
@@ -132,7 +132,7 @@
else:
ll_func = ll_list_is_true_foldable
return hop.gendirectcall(ll_func, v_lst)
-
+
def rtype_method_reverse(self, hop):
v_lst, = hop.inputargs(self)
hop.exception_cannot_occur()
@@ -273,7 +273,7 @@
return pair(r_lst, r_int).rtype_getitem(hop, checkidx=True)
rtype_getitem_idx_key = rtype_getitem_idx
-
+
def rtype_setitem((r_lst, r_int), hop):
if hop.has_implicit_exception(IndexError):
spec = dum_checkidx
@@ -331,7 +331,7 @@
## return hop.gendirectcall(ll_both_none, v_lst1, v_lst2)
## return pairtype(Repr, Repr).rtype_is_(pair(r_lst1, r_lst2), hop)
-
+
def rtype_eq((r_lst1, r_lst2), hop):
assert r_lst1.item_repr == r_lst2.item_repr
v_lst1, v_lst2 = hop.inputargs(r_lst1, r_lst2)
@@ -499,7 +499,7 @@
else:
check = item
if (not malloc_zero_filled) or check: # as long as malloc it is known to zero the allocated memory avoid zeroing twice
-
+
i = 0
while i < count:
l.ll_setitem_fast(i, item)
@@ -633,7 +633,6 @@
l.ll_setitem_fast(index, null)
l._ll_resize_le(newlength)
return res
-ll_pop_default.oopspec = 'list.pop(l)'
def ll_pop_zero(func, l):
length = l.ll_length()
More information about the pypy-commit
mailing list