[pypy-svn] r70462 - in pypy/trunk/pypy: jit/metainterp rlib rpython rpython/lltypesystem rpython/test
arigo at codespeak.net
arigo at codespeak.net
Fri Jan 8 21:55:16 CET 2010
Author: arigo
Date: Fri Jan 8 21:55:15 2010
New Revision: 70462
Modified:
pypy/trunk/pypy/jit/metainterp/codewriter.py
pypy/trunk/pypy/jit/metainterp/policy.py
pypy/trunk/pypy/rlib/rgc.py
pypy/trunk/pypy/rpython/lltypesystem/rlist.py
pypy/trunk/pypy/rpython/rlist.py
pypy/trunk/pypy/rpython/test/test_rlist.py
Log:
Merge branch/morearraycopy: use rgc.ll_arraycopy more or
less systematically.
Modified: pypy/trunk/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/trunk/pypy/jit/metainterp/codewriter.py Fri Jan 8 21:55:15 2010
@@ -86,12 +86,22 @@
if leave_graph is not None:
todo.append(leave_graph)
self.candidate_graphs = seen = set(todo)
+
+ def callers():
+ graph = top_graph
+ print graph
+ while graph in coming_from:
+ graph = coming_from[graph]
+ print '<-', graph
+ coming_from = {}
+
while todo:
top_graph = todo.pop()
for _, op in top_graph.iterblockops():
if op.opname not in ("direct_call", "indirect_call", "oosend"):
continue
kind = self.guess_call_kind(op, is_candidate)
+ # use callers() to view the calling chain in pdb
if kind != "regular":
continue
for graph in self.graphs_from(op, is_candidate):
@@ -100,6 +110,7 @@
assert is_candidate(graph)
todo.append(graph)
seen.add(graph)
+ coming_from[graph] = top_graph
return self.candidate_graphs
def graphs_from(self, op, is_candidate=None):
Modified: pypy/trunk/pypy/jit/metainterp/policy.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/policy.py (original)
+++ pypy/trunk/pypy/jit/metainterp/policy.py Fri Jan 8 21:55:15 2010
@@ -49,8 +49,6 @@
def look_inside_graph(self, graph):
from pypy.translator.backendopt.support import find_backedges
contains_loop = bool(find_backedges(graph))
- unsupported = contains_unsupported_variable_type(graph,
- self.supports_floats)
try:
func = graph.func
except AttributeError:
@@ -61,7 +59,8 @@
contains_loop = contains_loop and not getattr(
func, '_jit_unroll_safe_', False)
- res = see_function and not unsupported
+ res = see_function and not contains_unsupported_variable_type(graph,
+ self.supports_floats)
if res and contains_loop:
self.unsafe_loopy_graphs.add(graph)
return res and not contains_loop
Modified: pypy/trunk/pypy/rlib/rgc.py
==============================================================================
--- pypy/trunk/pypy/rlib/rgc.py (original)
+++ pypy/trunk/pypy/rlib/rgc.py Fri Jan 8 21:55:15 2010
@@ -1,5 +1,7 @@
import gc
from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rlib.objectmodel import we_are_translated
+
# ____________________________________________________________
# General GC features
@@ -334,7 +336,12 @@
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rlib.objectmodel import keepalive_until_here
- assert source != dest
+ # supports non-overlapping copies only
+ if not we_are_translated():
+ if source == dest:
+ assert (source_start + length <= dest_start or
+ dest_start + length <= source_start)
+
TP = lltype.typeOf(source).TO
assert TP == lltype.typeOf(dest).TO
if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
@@ -357,6 +364,7 @@
keepalive_until_here(source)
keepalive_until_here(dest)
ll_arraycopy._annspecialcase_ = 'specialize:ll'
+ll_arraycopy._jit_look_inside_ = False
def no_collect(func):
func._dont_inline_ = True
Modified: pypy/trunk/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rlist.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rlist.py Fri Jan 8 21:55:15 2010
@@ -368,8 +368,7 @@
else:
LIST = typeOf(l).TO
newitems = malloc(LIST.items.TO, n)
- for i in range(n):
- newitems[i] = olditems[i]
+ rgc.ll_arraycopy(olditems, newitems, 0, 0, n)
return newitems
ll_list2fixed.oopspec = 'list.list2fixed(l)'
Modified: pypy/trunk/pypy/rpython/rlist.py
==============================================================================
--- pypy/trunk/pypy/rpython/rlist.py (original)
+++ pypy/trunk/pypy/rpython/rlist.py Fri Jan 8 21:55:15 2010
@@ -11,6 +11,7 @@
from pypy.rlib.debug import ll_assert
from pypy.rlib.rarithmetic import ovfcheck, widen
from pypy.rpython.annlowlevel import ADTInterface
+from pypy.rlib import rgc
ADTIFixedList = ADTInterface(None, {
'll_newlist': (['SELF', Signed ], 'self'),
@@ -525,13 +526,24 @@
return LIST.ITEM
+def ll_arraycopy(source, dest, source_start, dest_start, length):
+ SRCTYPE = typeOf(source)
+ if isinstance(SRCTYPE, Ptr):
+ # lltype
+ rgc.ll_arraycopy(source.ll_items(), dest.ll_items(),
+ source_start, dest_start, length)
+ else:
+ # ootype -- XXX improve the case of array->array copy?
+ i = 0
+ while i < length:
+ item = source.ll_getitem_fast(source_start + i)
+ dest.ll_setitem_fast(dest_start + i, item)
+ i += 1
+
def ll_copy(RESLIST, l):
length = l.ll_length()
new_lst = RESLIST.ll_newlist(length)
- i = 0
- while i < length:
- new_lst.ll_setitem_fast(i, l.ll_getitem_fast(i))
- i += 1
+ ll_arraycopy(l, new_lst, 0, 0, length)
return new_lst
def ll_len(l):
@@ -574,15 +586,8 @@
except OverflowError:
raise MemoryError
l = RESLIST.ll_newlist(newlength)
- j = 0
- while j < len1:
- l.ll_setitem_fast(j, l1.ll_getitem_fast(j))
- j += 1
- i = 0
- while i < len2:
- l.ll_setitem_fast(j, l2.ll_getitem_fast(i))
- i += 1
- j += 1
+ ll_arraycopy(l1, l, 0, 0, len1)
+ ll_arraycopy(l2, l, 0, len1, len2)
return l
def ll_insert_nonneg(l, index, newitem):
@@ -769,12 +774,7 @@
except OverflowError:
raise MemoryError
l1._ll_resize_ge(newlength)
- i = 0
- j = len1
- while i < len2:
- l1.ll_setitem_fast(j, l2.ll_getitem_fast(i))
- i += 1
- j += 1
+ ll_arraycopy(l2, l1, 0, len1, len2)
ll_extend.oopspec = 'list.extend(l1, l2)'
def ll_extend_with_str(lst, s, getstrlen, getstritem):
@@ -867,12 +867,7 @@
ll_assert(start <= len1, "list slice start larger than list length")
newlength = len1 - start
l = RESLIST.ll_newlist(newlength)
- j = 0
- i = start
- while i < len1:
- l.ll_setitem_fast(j, l1.ll_getitem_fast(i))
- i += 1
- j += 1
+ ll_arraycopy(l1, l, start, 0, newlength)
return l
ll_listslice_startonly._annenforceargs_ = (None, None, int)
@@ -885,22 +880,14 @@
stop = length
newlength = stop - start
l = RESLIST.ll_newlist(newlength)
- j = 0
- i = start
- while i < stop:
- l.ll_setitem_fast(j, l1.ll_getitem_fast(i))
- i += 1
- j += 1
+ ll_arraycopy(l1, l, start, 0, newlength)
return l
def ll_listslice_minusone(RESLIST, l1):
newlength = l1.ll_length() - 1
ll_assert(newlength >= 0, "empty list is sliced with [:-1]")
l = RESLIST.ll_newlist(newlength)
- j = 0
- while j < newlength:
- l.ll_setitem_fast(j, l1.ll_getitem_fast(j))
- j += 1
+ ll_arraycopy(l1, l, 0, 0, newlength)
return l
def ll_listdelslice_startonly(l, start):
@@ -945,13 +932,8 @@
ll_assert(start <= l1.ll_length(), "l[start:x] = l with start > len(l)")
ll_assert(count == stop - start,
"setslice cannot resize lists in RPython")
- # XXX but it should be easy enough to support, soon
- j = start
- i = 0
- while i < count:
- l1.ll_setitem_fast(j, l2.ll_getitem_fast(i))
- i += 1
- j += 1
+ # XXX ...but it would be easy enough to support if really needed
+ ll_arraycopy(l2, l1, 0, start, count)
ll_listsetslice.oopspec = 'list.setslice(l1, start, stop, l2)'
# ____________________________________________________________
Modified: pypy/trunk/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/trunk/pypy/rpython/test/test_rlist.py (original)
+++ pypy/trunk/pypy/rpython/test/test_rlist.py Fri Jan 8 21:55:15 2010
@@ -410,13 +410,18 @@
assert res.item2 == 9
def test_bltn_list(self):
- def dummyfn():
- l1 = [42]
- l2 = list(l1)
- l2[0] = 0
- return l1[0]
- res = self.interpret(dummyfn, ())
- assert res == 42
+ # test for ll_copy()
+ for resize1 in [False, True]:
+ for resize2 in [False, True]:
+ def dummyfn():
+ l1 = [42]
+ if resize1: l1.append(43)
+ l2 = list(l1)
+ if resize2: l2.append(44)
+ l2[0] = 0
+ return l1[0]
+ res = self.interpret(dummyfn, ())
+ assert res == 42
def test_is_true(self):
def is_true(lst):
More information about the Pypy-commit
mailing list