Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch:
Changeset: r95981:9d4fe930924e
Date: 2019-02-12 20:11 +0100
http://bitbucket.org/pypy/pypy/changeset/9d4fe930924e/
Log: merge promote-unicode
mostly for completeness sake: support for rlib.jit.promote_unicode,
which behaves like promote_string, but for rpython unicode objects.
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -28,3 +28,8 @@
.. branch: regalloc-playground
Improve register allocation in the JIT.
+
+
+.. branch: promote-unicode
+
+Implement rlib.jit.promote_unicode to complement promote_string
diff --git a/rpython/jit/codewriter/jtransform.py
b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -596,6 +596,23 @@
op1 = SpaceOperation('str_guard_value', [op.args[0], c, descr],
op.result)
return [SpaceOperation('-live-', [], None), op1, None]
+ if (hints.get('promote_unicode') and
+ op.args[0].concretetype is not lltype.Void):
+ U = lltype.Ptr(rstr.UNICODE)
+ assert op.args[0].concretetype == U
+ self._register_extra_helper(EffectInfo.OS_UNIEQ_NONNULL,
+ "str.eq_nonnull",
+ [U, U],
+ lltype.Signed,
+ EffectInfo.EF_ELIDABLE_CANNOT_RAISE)
+ descr, p =
self.callcontrol.callinfocollection.callinfo_for_oopspec(
+ EffectInfo.OS_UNIEQ_NONNULL)
+ # XXX this is fairly ugly way of creating a constant,
+ # however, callinfocollection has no better interface
+ c = Constant(p.adr.ptr, lltype.typeOf(p.adr.ptr))
+ op1 = SpaceOperation('str_guard_value', [op.args[0], c, descr],
+ op.result)
+ return [SpaceOperation('-live-', [], None), op1, None]
if hints.get('force_virtualizable'):
return SpaceOperation('hint_force_virtualizable', [op.args[0]],
None)
if hints.get('force_no_const'): # for tests only
diff --git a/rpython/jit/codewriter/test/test_jtransform.py
b/rpython/jit/codewriter/test/test_jtransform.py
--- a/rpython/jit/codewriter/test/test_jtransform.py
+++ b/rpython/jit/codewriter/test/test_jtransform.py
@@ -94,7 +94,7 @@
return True
return False
def callinfo_for_oopspec(self, oopspecindex):
- assert oopspecindex == effectinfo.EffectInfo.OS_STREQ_NONNULL
+ # assert oopspecindex == effectinfo.EffectInfo.OS_STREQ_NONNULL
class c:
class adr:
ptr = 1
@@ -1129,6 +1129,21 @@
assert op1.result == v2
assert op0.opname == '-live-'
+def test_unicode_promote():
+ PUNICODE = lltype.Ptr(rstr.UNICODE)
+ v1 = varoftype(PUNICODE)
+ v2 = varoftype(PUNICODE)
+ op = SpaceOperation('hint',
+ [v1, Constant({'promote_unicode': True}, lltype.Void)],
+ v2)
+ tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
+ op0, op1, _ = tr.rewrite_operation(op)
+ assert op1.opname == 'str_guard_value'
+ assert op1.args[0] == v1
+ assert op1.args[2] == 'calldescr'
+ assert op1.result == v2
+ assert op0.opname == '-live-'
+
def test_double_promote_str():
PSTR = lltype.Ptr(rstr.STR)
v1 = varoftype(PSTR)
diff --git a/rpython/jit/metainterp/test/test_string.py
b/rpython/jit/metainterp/test/test_string.py
--- a/rpython/jit/metainterp/test/test_string.py
+++ b/rpython/jit/metainterp/test/test_string.py
@@ -3,7 +3,7 @@
from rpython.jit.metainterp.test.support import LLJitMixin
from rpython.rlib.debug import debug_print
from rpython.rlib.jit import (JitDriver, dont_look_inside, we_are_jitted,
- promote_string)
+ promote_string, promote_unicode)
from rpython.rlib.rstring import StringBuilder, UnicodeBuilder
@@ -518,6 +518,19 @@
self.meta_interp(f, [0])
self.check_resops(call_r=2, call_i=5)
+ def test_promote_unicode(self):
+ driver = JitDriver(greens = [], reds = ['n'])
+
+ def f(n):
+ while n < 21:
+ driver.jit_merge_point(n=n)
+ promote_unicode(unicode(str(n % 3)))
+ n += 1
+ return 0
+
+ self.meta_interp(f, [0])
+ self.check_resops(call_r=4, call_i=5)
+
def test_join_chars(self):
jitdriver = JitDriver(reds=['a', 'b', 'c', 'i'], greens=[])
_str = self._str
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -84,6 +84,7 @@
* promote - promote the argument from a variable into a constant
* promote_string - same, but promote string by *value*
+ * promote_unicode - same, but promote unicode string by *value*
* access_directly - directly access a virtualizable, as a structure
and don't treat it as a virtualizable
* fresh_virtualizable - means that virtualizable was just allocated.
@@ -126,6 +127,9 @@
def promote_string(x):
return hint(x, promote_string=True)
+def promote_unicode(x):
+ return hint(x, promote_unicode=True)
+
def dont_look_inside(func):
""" Make sure the JIT does not trace inside decorated function
(it becomes a call instead)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit