[pypy-commit] pypy promote-unicode: Introduce promote_unicode().
Corbin Simpson
noreply at buildbot.pypy.org
Thu Jul 3 20:36:04 CEST 2014
Author: Corbin Simpson <cds at corbinsimpson.com>
Branch: promote-unicode
Changeset: r72336:3489a054a745
Date: 2014-07-03 11:35 -0700
http://bitbucket.org/pypy/pypy/changeset/3489a054a745/
Log: Introduce promote_unicode().
This is a companion to promote_string() which promotes Unicode
strings by value. To use, simply ``from rpython.rlib.jit import
promote_unicode`` and then ``promote_unicode(any_unicode_string)``.
A few tests are included, and a couple bits of testing mocks were
improved to permit tests to not fail.
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
@@ -571,6 +571,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
@@ -107,7 +107,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
@@ -1059,6 +1059,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/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -60,6 +60,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.
@@ -79,6 +80,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)
More information about the pypy-commit
mailing list