Author: Antonio Cuni <[email protected]>
Branch: virtual-raw-mallocs
Changeset: r59479:37b9377a7717
Date: 2012-12-18 00:48 +0100
http://bitbucket.org/pypy/pypy/changeset/37b9377a7717/
Log: first passing test: very simple and lots of things still to do
(starting from forcing)
diff --git a/pypy/jit/metainterp/optimizeopt/earlyforce.py
b/pypy/jit/metainterp/optimizeopt/earlyforce.py
--- a/pypy/jit/metainterp/optimizeopt/earlyforce.py
+++ b/pypy/jit/metainterp/optimizeopt/earlyforce.py
@@ -1,3 +1,4 @@
+from pypy.jit.codewriter.effectinfo import EffectInfo
from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
from pypy.jit.metainterp.optimizeopt.vstring import VAbstractStringValue
from pypy.jit.metainterp.resoperation import rop, ResOperation
@@ -5,11 +6,19 @@
class OptEarlyForce(Optimization):
def propagate_forward(self, op):
opnum = op.getopnum()
+ def is_raw_free():
+ if opnum != rop.CALL:
+ return False
+ einfo = op.getdescr().get_extra_info()
+ return einfo.oopspecindex == EffectInfo.OS_RAW_FREE
+
if (opnum != rop.SETFIELD_GC and
opnum != rop.SETARRAYITEM_GC and
+ opnum != rop.SETARRAYITEM_RAW and
opnum != rop.QUASIIMMUT_FIELD and
opnum != rop.SAME_AS and
- opnum != rop.MARK_OPAQUE_PTR):
+ opnum != rop.MARK_OPAQUE_PTR and
+ not is_raw_free()):
for arg in op.getarglist():
if arg in self.optimizer.values:
diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py
b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -231,6 +231,12 @@
def setitem(self, index, value):
raise NotImplementedError
+ def getitem_raw(self, index):
+ raise NotImplementedError
+
+ def setitem_raw(self, index, value):
+ raise NotImplementedError
+
def getinteriorfield(self, index, ofs, default):
raise NotImplementedError
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -1742,6 +1742,21 @@
# We cannot track virtuals that survive for more than two iterations.
self.optimize_loop(ops, expected, preamble)
+ def test_virtual_raw_malloc(self):
+ ops = """
+ [i1]
+ i2 = call('malloc', 10, descr=raw_malloc_descr)
+ setarrayitem_raw(i2, 0, i1, descr=arraydescr)
+ i3 = getarrayitem_raw(i2, 0, descr=arraydescr)
+ call('free', i2, descr=raw_free_descr)
+ jump(i3)
+ """
+ expected = """
+ [i1]
+ jump(i1)
+ """
+ self.optimize_loop(ops, expected)
+
def test_duplicate_getfield_1(self):
ops = """
[p1, p2]
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
@@ -196,6 +196,15 @@
EffectInfo.EF_CANNOT_RAISE,
oopspecindex=EffectInfo.OS_ARRAYCOPY))
+ raw_malloc_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
+ EffectInfo([], [], [], [],
+ EffectInfo.EF_CAN_RAISE,
+ oopspecindex=EffectInfo.OS_RAW_MALLOC_VARSIZE))
+ raw_free_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
+ EffectInfo([], [], [], [],
+ EffectInfo.EF_CANNOT_RAISE,
+ oopspecindex=EffectInfo.OS_RAW_FREE))
+
# array of structs (complex data)
complexarray = lltype.GcArray(
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
@@ -1,4 +1,5 @@
from pypy.jit.codewriter.heaptracker import vtable2descr
+from pypy.jit.codewriter.effectinfo import EffectInfo
from pypy.jit.metainterp.executor import execute
from pypy.jit.metainterp.history import Const, ConstInt, BoxInt
from pypy.jit.metainterp.optimizeopt import optimizer
@@ -361,6 +362,24 @@
return modifier.make_varraystruct(self.arraydescr,
self._get_list_of_descrs())
+class VirtualRawMemoryValue(AbstractVirtualValue):
+
+ def __init__(self, cpu, size, keybox, source_op):
+ AbstractVirtualValue.__init__(self, keybox, source_op)
+ self.cpu = cpu
+ self.size = size
+ self._raw_items = {}
+
+ def _really_force(self, optforce):
+ import pdb;pdb.set_trace()
+
+ def setitem_raw(self, index, value):
+ self._raw_items[index] = value
+
+ def getitem_raw(self, index):
+ return self._raw_items[index]
+
+
class OptVirtualize(optimizer.Optimization):
"Virtualize objects until they escape."
@@ -386,6 +405,11 @@
self.make_equal_to(box, vvalue)
return vvalue
+ def make_virtual_raw_memory(self, size, box, source_op):
+ vvalue = VirtualRawMemoryValue(self.optimizer.cpu, size, box,
source_op)
+ self.make_equal_to(box, vvalue)
+ return vvalue
+
def optimize_VIRTUAL_REF(self, op):
indexbox = op.getarg(1)
#
@@ -490,6 +514,29 @@
self.getvalue(op.result).ensure_nonnull()
self.emit_operation(op)
+ 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)
+ elif effectinfo.oopspecindex == EffectInfo.OS_RAW_FREE:
+ self.do_RAW_FREE(op)
+ else:
+ self.emit_operation(op)
+
+ def do_RAW_MALLOC_VARSIZE(self, op):
+ sizebox = op.getarg(1)
+ if not isinstance(sizebox, ConstInt):
+ self.emit_operation(op)
+ return
+ size = sizebox.value
+ self.make_virtual_raw_memory(size, op.result, op)
+
+ def do_RAW_FREE(self, op):
+ value = self.getvalue(op.getarg(1))
+ if value.is_virtual():
+ return
+ self.emit_operation(op)
+
def optimize_ARRAYLEN_GC(self, op):
value = self.getvalue(op.getarg(0))
if value.is_virtual():
@@ -524,6 +571,29 @@
value.ensure_nonnull()
self.emit_operation(op)
+ def optimize_GETARRAYITEM_RAW(self, op):
+ value = self.getvalue(op.getarg(0))
+ if value.is_virtual():
+ indexbox = self.get_constant_box(op.getarg(1))
+ if indexbox is not None:
+ itemvalue = value.getitem_raw(indexbox.getint())
+ self.make_equal_to(op.result, itemvalue)
+ return
+ value.ensure_nonnull()
+ self.emit_operation(op)
+
+ def optimize_SETARRAYITEM_RAW(self, op):
+ value = self.getvalue(op.getarg(0))
+ if value.is_virtual():
+ indexbox = self.get_constant_box(op.getarg(1))
+ if indexbox is not None:
+ # XXX: we should check that the descr is always the same, or
+ # we might get wrong results
+ value.setitem_raw(indexbox.getint(),
self.getvalue(op.getarg(2)))
+ return
+ value.ensure_nonnull()
+ self.emit_operation(op)
+
def optimize_GETINTERIORFIELD_GC(self, op):
value = self.getvalue(op.getarg(0))
if value.is_virtual():
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit