Author: Alex Gaynor <[email protected]>
Branch: jit-resizable-list
Changeset: r44597:2bf2ca126e01
Date: 2011-05-30 10:52 -0700
http://bitbucket.org/pypy/pypy/changeset/2bf2ca126e01/
Log: Support the same virtual resize magic with resize_le, allow inlining
into default pop() (I don't think this effects app level code yet),
and a small optimization for int_floordiv(i0, 1), which I'll add
more tests for and port to default.
diff --git a/pypy/jit/codewriter/effectinfo.py
b/pypy/jit/codewriter/effectinfo.py
--- a/pypy/jit/codewriter/effectinfo.py
+++ b/pypy/jit/codewriter/effectinfo.py
@@ -76,6 +76,7 @@
OS_MATH_SQRT = 100
OS_LIST_RESIZE_GE = 120
+ OS_LIST_RESIZE_LE = 121
def __new__(cls, readonly_descrs_fields,
write_descrs_fields, write_descrs_arrays,
@@ -92,7 +93,7 @@
result = object.__new__(cls)
result.readonly_descrs_fields = readonly_descrs_fields
if extraeffect == EffectInfo.EF_LOOPINVARIANT or \
- extraeffect == EffectInfo.EF_PURE:
+ extraeffect == EffectInfo.EF_PURE:
result.write_descrs_fields = []
result.write_descrs_arrays = []
else:
diff --git a/pypy/jit/codewriter/jtransform.py
b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -1236,6 +1236,9 @@
def do_resizable_list__resize_ge(self, op, args, arraydescr, lengthdescr,
itemsdescr, structdescr):
return self._handle_oopspec_call(op, args,
EffectInfo.OS_LIST_RESIZE_GE)
+ def do_resizable_list__resize_le(self, op, args, arraydescr, lengthdescr,
+ itemsdescr, structdescr):
+ return self._handle_oopspec_call(op, args,
EffectInfo.OS_LIST_RESIZE_LE)
# ----------
@@ -1379,10 +1382,10 @@
assert vinfo is not None
self.vable_flags[op.args[0]] = op.args[2].value
return []
-
+
# ---------
# ll_math.sqrt_nonneg()
-
+
def _handle_math_sqrt_call(self, op, oopspec_name, args):
return self._handle_oopspec_call(op, args, EffectInfo.OS_MATH_SQRT,
EffectInfo.EF_PURE)
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -399,6 +399,9 @@
v1 = self.getvalue(op.getarg(0))
v2 = self.getvalue(op.getarg(1))
+ if v2.is_constant() and v2.box.getint() == 1:
+ self.make_equal_to(op.result, v1)
+ return
if v1.intbound.known_ge(IntBound(0, 0)) and v2.is_constant():
val = v2.box.getint()
if val & (val - 1) == 0 and val > 0: # val == 2**shift
diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py
b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -336,6 +336,9 @@
elif oopspecindex == EffectInfo.OS_LIST_RESIZE_GE:
if self._optimize_CALL_LIST_RESIZE_GE(op):
return
+ elif oopspecindex == EffectInfo.OS_LIST_RESIZE_LE:
+ if self._optimize_CALL_LIST_RESIZE_LE(op):
+ return
self.emit_operation(op)
def optimize_VIRTUAL_REF(self, op):
@@ -377,7 +380,7 @@
if not self.optimizer.cpu.ts.CONST_NULL.same_constant(objbox):
seo(ResOperation(rop.SETFIELD_GC, op.getarglist(), None,
descr = vrefinfo.descr_forced))
-
+
# - set 'virtual_token' to TOKEN_NONE
args = [op.getarg(0), ConstInt(vrefinfo.TOKEN_NONE)]
seo(ResOperation(rop.SETFIELD_GC, args, None,
@@ -491,7 +494,7 @@
return True # 0-length arraycopy
return False
- def _optimize_CALL_LIST_RESIZE_GE(self, op):
+ def _optimize_CALL_LIST_RESIZE(self, op):
list_value = self.getvalue(op.getarg(1))
newsize_value = self.getvalue(op.getarg(2))
newsize_box = self.get_constant_box(op.getarg(2))
@@ -508,6 +511,7 @@
list_value.setfield(length_descr, newsize_value)
return True
return False
+ _optimize_CALL_LIST_RESIZE_LE = _optimize_CALL_LIST_RESIZE_GE =
_optimize_CALL_LIST_RESIZE
def propagate_forward(self, op):
opnum = op.getopnum()
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
@@ -218,6 +218,7 @@
lst += [1]
n -= len(lst)
s += lst[0]
+ s /= lst.pop()
return s
res = self.meta_interp(f, [15], listops=True)
assert res == f(15)
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
@@ -244,7 +244,7 @@
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
@@ -255,7 +255,7 @@
def ll_both_none(lst1, lst2):
return not lst1 and not lst2
-
+
# ____________________________________________________________
#
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)
@@ -498,7 +498,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)
@@ -632,7 +632,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()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit