Author: Maciej Fijalkowski <[email protected]>
Branch: string-promote-2
Changeset: r47930:b2a87ed6e142
Date: 2011-10-09 22:23 +0200
http://bitbucket.org/pypy/pypy/changeset/b2a87ed6e142/
Log: codewriter support for promoting strings
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
@@ -455,12 +455,20 @@
# the special return value None forces op.result to be considered
# equal to op.args[0]
return [op0, op1, None]
- if (hints.get('string_promote') and
+ if (hints.get('promote_string') and
op.args[0].concretetype is not lltype.Void):
- assert op.args[0].concretetype == lltype.Ptr(rstr.STR)
- op0 = SpaceOperation('-live-', [], None)
- op1 = SpaceOperation('str_guard_value', [op.args[0]], op.result)
- return [op0, op1, None]
+ S = lltype.Ptr(rstr.STR)
+ assert op.args[0].concretetype == S
+ self._register_extra_helper(EffectInfo.OS_STREQ_NONNULL,
+ "str.eq_nonnull",
+ [S, S],
+ lltype.Signed,
+ EffectInfo.EF_ELIDABLE_CANNOT_RAISE)
+ descr = self.callcontrol.callinfo_for_oopspec(
+ EffectInfo.OS_STREQ_NONNULL)
+ op1 = SpaceOperation('str_guard_value', [op.args[0], descr],
+ op.result)
+ return op1
else:
log.WARNING('ignoring hint %r at %r' % (hints, self.graph))
@@ -1431,6 +1439,7 @@
func = heaptracker.adr2int(
llmemory.cast_ptr_to_adr(c_func.value))
self.callcontrol.callinfocollection.add(oopspecindex, calldescr, func)
+ return calldescr
def _handle_stroruni_call(self, op, oopspec_name, args):
SoU = args[0].concretetype # Ptr(STR) or Ptr(UNICODE)
diff --git a/pypy/jit/codewriter/test/test_jtransform.py
b/pypy/jit/codewriter/test/test_jtransform.py
--- a/pypy/jit/codewriter/test/test_jtransform.py
+++ b/pypy/jit/codewriter/test/test_jtransform.py
@@ -119,6 +119,7 @@
EI.OS_STR2UNICODE:([PSTR], PUNICODE),
EI.OS_STR_CONCAT: ([PSTR, PSTR], PSTR),
EI.OS_STR_SLICE: ([PSTR, INT, INT], PSTR),
+ EI.OS_STREQ_NONNULL: ([PSTR, PSTR], INT),
EI.OS_UNI_CONCAT: ([PUNICODE, PUNICODE], PUNICODE),
EI.OS_UNI_SLICE: ([PUNICODE, INT, INT], PUNICODE),
EI.OS_UNI_EQUAL: ([PUNICODE, PUNICODE], lltype.Bool),
@@ -140,6 +141,9 @@
return 'calldescr-%d' % oopspecindex
def calldescr_canraise(self, calldescr):
return False
+ def callinfo_for_oopspec(self, oopspecindex):
+ assert oopspecindex == effectinfo.EffectInfo.OS_STREQ_NONNULL
+ return 'calldescr'
def test_optimize_goto_if_not():
@@ -849,14 +853,13 @@
v1 = varoftype(PSTR)
v2 = varoftype(PSTR)
op = SpaceOperation('hint',
- [v1, Constant({'string_promote': True}, lltype.Void)],
+ [v1, Constant({'promote_string': True}, lltype.Void)],
v2)
tr = Transformer(FakeCPU(), FakeBuiltinCallControl())
- op0, op1, _ = tr.rewrite_operation(op)
- assert op0.opname == '-live-'
- assert op1.opname == 'str_guard_value'
- assert op1.args == [v1]
- assert op1.result == v2
+ op0 = tr.rewrite_operation(op)
+ assert op0.opname == 'str_guard_value'
+ assert op0.args == [v1, 'calldescr']
+ assert op0.result == v2
def test_unicode_concat():
# test that the oopspec is present and correctly transformed
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit