[pypy-svn] r61937 - in pypy/branch/pyjitpl5/pypy/jit: backend/llgraph metainterp metainterp/test
fijal at codespeak.net
fijal at codespeak.net
Sun Feb 15 15:03:16 CET 2009
Author: fijal
Date: Sun Feb 15 15:03:16 2009
New Revision: 61937
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py
Log:
Support for list.nonzero. Next step - make tlc use virtualizables
in a nice way
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/llgraph/llimpl.py Sun Feb 15 15:03:16 2009
@@ -90,6 +90,7 @@
'insert' : (('void', 'ptr', 'int', 'int'), None),
'pop' : (('void', 'ptr',), 'int'),
'len' : (('void', 'ptr',), 'int'),
+ 'listnonzero' : (('void', 'ptr',), 'int'),
}
# ____________________________________________________________
@@ -774,12 +775,16 @@
op_insert = op_listop
op_pop = op_listop_return
op_len = op_listop_return
+ op_listnonzero = op_listop_return
def op_newlist(self, ll_newlist, lgt, default_val=None):
res = self.do_call(ll_newlist, lgt)
if (default_val is not None and
isinstance(lltype.typeOf(default_val), lltype.Ptr)):
- TP = lltype.typeOf(res).TO.OF
+ if hasattr(res, 'items'):
+ TP = lltype.typeOf(res.items).TO.OF
+ else:
+ TP = lltype.typeOf(res).TO.OF
if default_val:
default_val = lltype.cast_opaque_ptr(TP, res)
else:
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py Sun Feb 15 15:03:16 2009
@@ -19,15 +19,16 @@
class ListDescr(BuiltinDescr):
def __init__(self, getfunc, setfunc, malloc_func, append_func,
- pop_func, insert_func, len_func, tp):
- self.setfunc = setfunc
- self.getfunc = getfunc
- self.malloc_func = malloc_func
- self.append_func = append_func
- self.insert_func = insert_func
- self.pop_func = pop_func
- self.len_func = len_func
- self.tp = tp
+ pop_func, insert_func, len_func, nonzero_func, tp):
+ self.setfunc = setfunc
+ self.getfunc = getfunc
+ self.malloc_func = malloc_func
+ self.append_func = append_func
+ self.insert_func = insert_func
+ self.pop_func = pop_func
+ self.len_func = len_func
+ self.nonzero_func = nonzero_func
+ self.tp = tp
def equals(self, other):
if isinstance(other, ListDescr):
@@ -164,6 +165,9 @@
[lltype.Signed], TP)
len_func, _ = support.builtin_func_for_spec(rtyper, 'list.len',
[TP], lltype.Signed)
+ nonzero_func, _ = support.builtin_func_for_spec(rtyper,
+ 'list.nonzero',
+ [TP], lltype.Bool)
if isinstance(TP.TO, lltype.GcStruct):
append_func, _ = support.builtin_func_for_spec(rtyper,
@@ -184,6 +188,7 @@
history.ConstAddr(append_func.value, self.cpu),
history.ConstAddr(pop_func.value, self.cpu),
history.ConstAddr(insert_func.value, self.cpu),
+ history.ConstAddr(nonzero_func.value, self.cpu),
history.ConstAddr(len_func.value, self.cpu),
tp)
else:
@@ -191,6 +196,7 @@
history.ConstAddr(setfunc.value, self.cpu),
history.ConstAddr(malloc_func.value, self.cpu),
None, None, None,
+ history.ConstAddr(nonzero_func.value, self.cpu),
history.ConstAddr(len_func.value, self.cpu),
tp)
self.list_cache[TP.TO] = ld
@@ -664,6 +670,8 @@
opname = 'len'
elif oopspec_name == 'list.insert':
opname = 'insert'
+ elif oopspec_name == 'list.nonzero':
+ opname = 'listnonzero'
else:
raise NotImplementedError("not supported %s" % oopspec_name)
self.emit(opname)
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py Sun Feb 15 15:03:16 2009
@@ -375,7 +375,7 @@
field = instnode.known_length
self.find_nodes_getfield(instnode, field, op.results[0])
continue
- elif opname == 'len':
+ elif opname == 'len' or opname == 'listnonzero':
instnode = self.getnode(op.args[1])
assert instnode.known_length != -1
lgtbox = op.results[0].constbox()
@@ -697,7 +697,7 @@
ofs = instnode.known_length
if self.optimize_getfield(instnode, ofs, op.results[0]):
continue
- elif opname == 'len':
+ elif opname == 'len' or opname == 'listnonzero':
instnode = self.nodes[op.args[1]]
assert instnode.known_length
continue
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py Sun Feb 15 15:03:16 2009
@@ -426,6 +426,11 @@
args = [descr.len_func] + varargs
self.execute_with_exc('len', args, 'int')
+ @arguments("builtin", "varargs")
+ def opimpl_listnonzero(self, descr, varargs):
+ args = [descr.nonzero_func] + varargs
+ self.execute_with_exc('listnonzero', args, 'int')
+
@arguments("indirectcallset", "box", "varargs")
def opimpl_indirect_call(self, indirectcallset, box, varargs):
assert isinstance(box, Const) # XXX
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vlist.py Sun Feb 15 15:03:16 2009
@@ -111,6 +111,26 @@
assert res == f(33)
self.check_all_virtualized()
+ def test_nonzero(self):
+ jitdriver = JitDriver(greens = [], reds = ['n'])
+ def f(n):
+ while n > 0:
+ jitdriver.can_enter_jit(n=n)
+ jitdriver.jit_merge_point(n=n)
+ lst = [1, 2, 3]
+ lst.insert(0, n)
+ # nonzero should go away
+ if not lst:
+ return -33
+ n = lst[0] - 1
+ lst.pop()
+ # last pop is needed, otherwise it won't work
+ return n
+ res = self.meta_interp(f, [33])
+ assert res == f(33)
+ self.check_all_virtualized()
+ self.check_loops(listnonzero=0, guard_true=1, guard_false=0)
+
def test_list_escapes(self):
py.test.skip("XXX")
def f(n):
More information about the Pypy-commit
mailing list