Author: Antonio Cuni <[email protected]>
Branch: virtual-raw-mallocs
Changeset: r59538:1ed143f0bfd8
Date: 2012-12-23 19:24 +0100
http://bitbucket.org/pypy/pypy/changeset/1ed143f0bfd8/
Log: apply the raw virtuals optimization only if we are allocating an
array of chars. With other types it's harder because the optimizer
does not know the size of the items, and it's not useful for cffi
anyway
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,12 +76,12 @@
#
OS_MATH_SQRT = 100
#
- OS_RAW_MALLOC_VARSIZE = 110
+ OS_RAW_MALLOC_VARSIZE_CHAR = 110
OS_RAW_FREE = 111
# for debugging:
_OS_CANRAISE = set([OS_NONE, OS_STR2UNICODE, OS_LIBFFI_CALL,
- OS_RAW_MALLOC_VARSIZE])
+ OS_RAW_MALLOC_VARSIZE_CHAR])
def __new__(cls, readonly_descrs_fields, readonly_descrs_arrays,
write_descrs_fields, write_descrs_arrays,
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
@@ -533,9 +533,11 @@
name += '_no_track_allocation'
op1 = self.prepare_builtin_call(op, name, args, (TYPE,), TYPE)
if name == 'raw_malloc_varsize':
- return self._handle_oopspec_call(op1, args,
- EffectInfo.OS_RAW_MALLOC_VARSIZE,
- EffectInfo.EF_CAN_RAISE)
+ ITEMTYPE = op.args[0].value.OF
+ if ITEMTYPE == lltype.Char:
+ return self._handle_oopspec_call(op1, args,
+
EffectInfo.OS_RAW_MALLOC_VARSIZE_CHAR,
+ EffectInfo.EF_CAN_RAISE)
return self.rewrite_op_direct_call(op1)
def rewrite_op_malloc_varsize(self, op):
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
@@ -123,7 +123,7 @@
INT = lltype.Signed
UNICHAR = lltype.UniChar
FLOAT = lltype.Float
- ARRAYPTR = rffi.CArrayPtr(lltype.Signed)
+ ARRAYPTR = rffi.CArrayPtr(lltype.Char)
argtypes = {
EI.OS_MATH_SQRT: ([FLOAT], FLOAT),
EI.OS_STR2UNICODE:([PSTR], PUNICODE),
@@ -140,7 +140,7 @@
EI.OS_UNIEQ_NONNULL_CHAR: ([PUNICODE, UNICHAR], INT),
EI.OS_UNIEQ_CHECKNULL_CHAR: ([PUNICODE, UNICHAR], INT),
EI.OS_UNIEQ_LENGTHOK: ([PUNICODE, PUNICODE], INT),
- EI.OS_RAW_MALLOC_VARSIZE: ([INT], ARRAYPTR),
+ EI.OS_RAW_MALLOC_VARSIZE_CHAR: ([INT], ARRAYPTR),
EI.OS_RAW_FREE: ([ARRAYPTR], lltype.Void),
}
argtypes = argtypes[oopspecindex]
@@ -148,7 +148,7 @@
assert argtypes[1] == op.result.concretetype
if oopspecindex == EI.OS_STR2UNICODE:
assert extraeffect == EI.EF_ELIDABLE_CAN_RAISE
- elif oopspecindex == EI.OS_RAW_MALLOC_VARSIZE:
+ elif oopspecindex == EI.OS_RAW_MALLOC_VARSIZE_CHAR:
assert extraeffect == EI.EF_CAN_RAISE
elif oopspecindex == EI.OS_RAW_FREE:
assert extraeffect == EI.EF_CANNOT_RAISE
@@ -158,7 +158,7 @@
def calldescr_canraise(self, calldescr):
EI = effectinfo.EffectInfo
- if calldescr == 'calldescr-%d' % EI.OS_RAW_MALLOC_VARSIZE:
+ if calldescr == 'calldescr-%d' % EI.OS_RAW_MALLOC_VARSIZE_CHAR:
return True
return False
@@ -552,7 +552,7 @@
assert op1.args == []
def test_raw_malloc():
- S = rffi.CArray(lltype.Signed)
+ S = rffi.CArray(lltype.Char)
v1 = varoftype(lltype.Signed)
v = varoftype(lltype.Ptr(S))
flags = Constant({'flavor': 'raw'}, lltype.Void)
@@ -563,7 +563,7 @@
assert op0.opname == 'residual_call_ir_i'
assert op0.args[0].value == 'raw_malloc_varsize' # pseudo-function as a str
assert (op0.args[-1] == 'calldescr-%d' %
- effectinfo.EffectInfo.OS_RAW_MALLOC_VARSIZE)
+ effectinfo.EffectInfo.OS_RAW_MALLOC_VARSIZE_CHAR)
assert op1.opname == '-live-'
assert op1.args == []
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_util.py
b/pypy/jit/metainterp/optimizeopt/test/test_util.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_util.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_util.py
@@ -199,7 +199,7 @@
raw_malloc_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
EffectInfo([], [], [], [],
EffectInfo.EF_CAN_RAISE,
- oopspecindex=EffectInfo.OS_RAW_MALLOC_VARSIZE))
+ oopspecindex=EffectInfo.OS_RAW_MALLOC_VARSIZE_CHAR))
raw_free_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
EffectInfo([], [], [], [],
EffectInfo.EF_CANNOT_RAISE,
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
@@ -612,14 +612,14 @@
def optimize_CALL(self, op):
effectinfo = op.getdescr().get_extra_info()
- if effectinfo.oopspecindex == EffectInfo.OS_RAW_MALLOC_VARSIZE:
- self.do_RAW_MALLOC_VARSIZE(op)
+ if effectinfo.oopspecindex == EffectInfo.OS_RAW_MALLOC_VARSIZE_CHAR:
+ self.do_RAW_MALLOC_VARSIZE_CHAR(op)
elif effectinfo.oopspecindex == EffectInfo.OS_RAW_FREE:
self.do_RAW_FREE(op)
else:
self.emit_operation(op)
- def do_RAW_MALLOC_VARSIZE(self, op):
+ def do_RAW_MALLOC_VARSIZE_CHAR(self, op):
sizebox = op.getarg(1)
if not isinstance(sizebox, ConstInt):
self.emit_operation(op)
diff --git a/pypy/jit/metainterp/resume.py b/pypy/jit/metainterp/resume.py
--- a/pypy/jit/metainterp/resume.py
+++ b/pypy/jit/metainterp/resume.py
@@ -896,7 +896,7 @@
def allocate_raw_buffer(self, size):
cic = self.metainterp.staticdata.callinfocollection
- calldescr, func =
cic.callinfo_for_oopspec(EffectInfo.OS_RAW_MALLOC_VARSIZE)
+ calldescr, func =
cic.callinfo_for_oopspec(EffectInfo.OS_RAW_MALLOC_VARSIZE_CHAR)
return self.metainterp.execute_and_record_varargs(
rop.CALL, [ConstInt(func), ConstInt(size)], calldescr)
diff --git a/pypy/jit/metainterp/test/test_virtual.py
b/pypy/jit/metainterp/test/test_virtual.py
--- a/pypy/jit/metainterp/test/test_virtual.py
+++ b/pypy/jit/metainterp/test/test_virtual.py
@@ -1265,6 +1265,25 @@
# the getarrayitem_raw is in the preamble
self.check_resops(getarrayitem_raw=1, setarrayitem_raw=0)
+ def test_raw_malloc_only_chars(self):
+ mydriver = JitDriver(greens=[], reds = 'auto')
+ def f(n):
+ i = 0
+ res = 0
+ while i < n:
+ mydriver.jit_merge_point()
+ # this is not virtualized because it's not a buffer of chars
+ buffer = lltype.malloc(rffi.LONGP.TO, 1, flavor='raw')
+ buffer[0] = i+1
+ res += buffer[0]
+ i = buffer[0]
+ lltype.free(buffer, flavor='raw')
+ return res
+ assert f(10) == 55
+ res = self.meta_interp(f, [10])
+ assert res == 55
+ self.check_trace_count(1)
+ self.check_resops(setarrayitem_raw=2, getarrayitem_raw=4)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit