Author: Maciej Fijalkowski <[email protected]>
Branch: optresult
Changeset: r77586:4222f1fbdb45
Date: 2015-05-26 16:26 +0200
http://bitbucket.org/pypy/pypy/changeset/4222f1fbdb45/
Log: basic strlen opts
diff --git a/rpython/jit/metainterp/optimizeopt/info.py
b/rpython/jit/metainterp/optimizeopt/info.py
--- a/rpython/jit/metainterp/optimizeopt/info.py
+++ b/rpython/jit/metainterp/optimizeopt/info.py
@@ -172,6 +172,25 @@
assert self.is_virtual()
return visitor.visit_vstruct(self.vdescr, fielddescrs)
+class StrPtrInfo(AbstractVirtualPtrInfo):
+ _attrs_ = ('length', 'lenbound')
+
+ length = -1
+ lenbound = None
+
+ def __init__(self):
+ pass
+
+ def getlenbound(self):
+ from rpython.jit.metainterp.optimizeopt import intutils
+
+ if self.lenbound is None:
+ if self.length == -1:
+ self.lenbound = intutils.IntBound(0, intutils.MAXINT)
+ else:
+ self.lenbound = intutils.ConstIntBound(self.length)
+ return self.lenbound
+
class ArrayPtrInfo(AbstractVirtualPtrInfo):
_attrs_ = ('length', '_items', 'lenbound', '_clear')
@@ -185,6 +204,11 @@
self._init_items(const, size, clear)
self._clear = clear
+ def getlenbound(self):
+ if self.lenbound is None:
+ xxx
+ return self.lenbound
+
def _init_items(self, const, size, clear):
self.length = size
if clear:
@@ -275,10 +299,6 @@
count += 1
i += 1
return count
-
-class StrPtrInfo(NonNullPtrInfo):
- _attrs_ = ()
-
class ConstPtrInfo(PtrInfo):
_attrs_ = ('_const',)
diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py
b/rpython/jit/metainterp/optimizeopt/intbounds.py
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -382,21 +382,13 @@
def optimize_STRLEN(self, op):
self.emit_operation(op)
- array = self.getvalue(op.getarg(0))
- result = self.getvalue(op)
- array.make_len_gt(MODE_STR, op.getdescr(), -1)
- array.getlenbound().bound.intersect(result.getintbound())
- assert isinstance(result, IntOptValue)
- result.intbound = array.getlenbound().bound
+ array = self.ensure_ptr_info_arg0(op)
+ self.get_box_replacement(op).set_forwarded(array.getlenbound())
def optimize_UNICODELEN(self, op):
self.emit_operation(op)
- array = self.getvalue(op.getarg(0))
- result = self.getvalue(op)
- array.make_len_gt(MODE_UNICODE, op.getdescr(), -1)
- array.getlenbound().bound.intersect(result.getintbound())
- assert isinstance(result, IntOptValue)
- result.intbound = array.getlenbound().bound
+ array = self.ensure_ptr_info_arg0(op)
+ self.get_box_replacement(op).set_forwarded(array.getlenbound())
def optimize_STRGETITEM(self, op):
self.emit_operation(op)
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -623,6 +623,8 @@
opinfo = info.ArrayPtrInfo(op.getdescr())
elif op.getopnum() == rop.GUARD_CLASS:
opinfo = info.InstancePtrInfo()
+ elif op.getopnum() in (rop.STRLEN, rop.UNICODELEN):
+ opinfo = info.StrPtrInfo()
else:
xxx
opinfo.last_guard_pos = last_guard_pos
diff --git a/rpython/jit/metainterp/optimizeopt/vstring.py
b/rpython/jit/metainterp/optimizeopt/vstring.py
--- a/rpython/jit/metainterp/optimizeopt/vstring.py
+++ b/rpython/jit/metainterp/optimizeopt/vstring.py
@@ -491,12 +491,13 @@
self._optimize_STRLEN(op, mode_unicode)
def _optimize_STRLEN(self, op, mode):
- value = self.getvalue(op.getarg(0))
- lengthbox = value.getstrlen(self, mode, op)
- if op in self.optimizer.values:
- assert self.getvalue(op) is self.getvalue(lengthbox)
- elif op is not lengthbox:
- self.make_equal_to(op, self.getvalue(lengthbox))
+ #value = self.getvalue(op.getarg(0))
+ #lengthbox = value.getstrlen(self, mode, op)
+ #if op in self.optimizer.values:
+ # assert self.getvalue(op) is self.getvalue(lengthbox)
+ #elif op is not lengthbox:
+ # self.make_equal_to(op, self.getvalue(lengthbox))
+ self.emit_operation(op)
def optimize_COPYSTRCONTENT(self, op):
self._optimize_COPYSTRCONTENT(op, mode_string)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit