[pypy-svn] r61781 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Feb 12 14:38:46 CET 2009
Author: arigo
Date: Thu Feb 12 14:38:44 2009
New Revision: 61781
Added:
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py (contents, props changed)
Modified:
pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
Log:
(fijal, arigo)
In-progress: virtualizables in optimize.py.
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py Thu Feb 12 14:38:44 2009
@@ -121,6 +121,7 @@
self.startbox = startbox
self.const = const
self.virtual = False
+ self.virtualized = False
self.cls = None
self.origfields = {}
self.curfields = {}
@@ -272,6 +273,10 @@
if instnode.cls is None:
instnode.cls = InstanceNode(op.args[1])
continue
+ elif opname.startswith('guard_nonvirtualized_'):
+ instnode = self.getnode(op.args[0])
+ instnode.virtualized = True
+ continue
elif opname not in ('oois', 'ooisnot',
'ooisnull', 'oononnull'):
# default case
@@ -297,7 +302,7 @@
while not done:
done = True
for instnode, fieldnode in self.dependency_graph:
- if instnode.escaped:
+ if instnode.escaped and not instnode.virtualized:
if not fieldnode.escaped:
fieldnode.escaped = True
done = False
@@ -412,6 +417,13 @@
op = self.optimize_guard(op)
newoperations.append(op)
continue
+ elif opname.startswith('guard_nonvirtualized_'):
+ instnode = self.nodes[op.args[0]]
+ if instnode.virtualized:
+ continue
+ op = self.optimize_guard(op)
+ newoperations.append(op)
+ continue
elif opname.startswith('guard_'):
if opname == 'guard_true' or opname == 'guard_false':
if self.nodes[op.args[0]].const:
@@ -421,7 +433,7 @@
continue
elif opname.startswith('getfield_gc_'):
instnode = self.nodes[op.args[0]]
- if instnode.virtual:
+ if instnode.virtual or instnode.virtualized:
ofs = op.args[1].getint()
assert ofs in instnode.curfields # xxx
self.nodes[op.results[0]] = instnode.curfields[ofs]
@@ -439,7 +451,7 @@
elif opname.startswith('setfield_gc_'):
instnode = self.nodes[op.args[0]]
valuenode = self.nodes[op.args[2]]
- if instnode.virtual:
+ if instnode.virtual or instnode.virtualized:
ofs = op.args[1].getint()
instnode.curfields[ofs] = valuenode
# XXX hack
Added: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py Thu Feb 12 14:38:44 2009
@@ -0,0 +1,115 @@
+from pypy.rpython.lltypesystem import lltype, rclass, llmemory
+from pypy.rpython.lltypesystem.rvirtualizable2 import VABLERTIPTR
+from pypy.rpython.lltypesystem.rvirtualizable2 import VirtualizableAccessor
+from pypy.jit.backend.llgraph import runner
+from pypy.jit.metainterp import heaptracker
+from pypy.jit.metainterp.history import (ResOperation, MergePoint, Jump,
+ ConstInt, ConstAddr, BoxInt, BoxPtr)
+from pypy.jit.metainterp.optimize import PerfectSpecializer
+from pypy.jit.metainterp.virtualizable import VirtualizableDesc
+from pypy.jit.metainterp.test.test_optimize import (cpu, NODE, node_vtable)
+
+# ____________________________________________________________
+
+XY = lltype.GcStruct(
+ 'XY',
+ ('parent', rclass.OBJECT),
+ ('vable_base', llmemory.Address),
+ ('vable_rti', VABLERTIPTR),
+ ('x', lltype.Signed),
+ ('node', lltype.Ptr(NODE)),
+ hints = {'virtualizable2': True},
+ adtmeths = {'access': VirtualizableAccessor()})
+XY._adtmeths['access'].initialize(XY, ['x', 'node'])
+
+xy_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
+xy_vtable.name = lltype.malloc(rclass.OBJECT_VTABLE.name.TO, 3, immortal=True)
+xy_vtable.name[0] = 'X'
+xy_vtable.name[1] = 'Y'
+xy_vtable.name[2] = '\x00'
+heaptracker.set_testing_vtable_for_gcstruct(XY, xy_vtable)
+
+XYSUB = lltype.GcStruct(
+ 'XYSUB',
+ ('parent', XY),
+ ('z', lltype.Signed),
+ hints = {'virtualizable2': True},
+ adtmeths = {'access': VirtualizableAccessor()})
+XYSUB._adtmeths['access'].initialize(XYSUB, ['z'], PARENT=XY)
+
+xysub_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
+xysub_vtable.name = lltype.malloc(rclass.OBJECT_VTABLE.name.TO, 6,
+ immortal=True)
+xysub_vtable.name[0] = 'X'
+xysub_vtable.name[1] = 'Y'
+xysub_vtable.name[2] = 'S'
+xysub_vtable.name[3] = 'U'
+xysub_vtable.name[4] = 'B'
+xysub_vtable.name[5] = '\x00'
+heaptracker.set_testing_vtable_for_gcstruct(XYSUB, xysub_vtable)
+
+# ____________________________________________________________
+
+xy_desc = VirtualizableDesc(cpu, XY)
+
+# ____________________________________________________________
+
+class A:
+ ofs_node = runner.CPU.offsetof(XY, 'node')
+ ofs_value = runner.CPU.offsetof(NODE, 'value')
+ size_of_node = runner.CPU.sizeof(NODE)
+ #
+ frame = lltype.malloc(XY)
+ frame.vable_rti = lltype.nullptr(XY.vable_rti.TO)
+ frame.node = lltype.malloc(NODE)
+ frame.node.value = 20
+ sum = BoxInt(0)
+ fr = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, frame))
+ n1 = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, frame.node))
+ nextnode = lltype.malloc(NODE)
+ nextnode.value = 19
+ n2 = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, nextnode))
+ v = BoxInt(frame.node.value)
+ v2 = BoxInt(nextnode.value)
+ sum2 = BoxInt(0 + frame.node.value)
+ ops = [
+ MergePoint('merge_point', [sum, fr], []),
+ ResOperation('guard_nonvirtualized__4', [fr, ConstInt(ofs_node)], []),
+ ResOperation('getfield_gc_ptr', [fr, ConstInt(ofs_node)], [n1]),
+ ResOperation('getfield_gc__4', [n1, ConstInt(ofs_value)], [v]),
+ ResOperation('int_sub', [v, ConstInt(1)], [v2]),
+ ResOperation('int_add', [sum, v], [sum2]),
+ ResOperation('new_with_vtable', [ConstInt(size_of_node),
+ ConstAddr(node_vtable, cpu)], [n2]),
+ ResOperation('setfield_gc__4', [n2, ConstInt(ofs_value), v2], []),
+ ResOperation('setfield_gc_ptr', [fr, ConstInt(ofs_node), n2], []),
+ Jump('jump', [sum2, fr], []),
+ ]
+ ops[1].desc = xy_desc
+
+def test_A_find_nodes():
+ spec = PerfectSpecializer(A.ops)
+ spec.find_nodes()
+ assert spec.nodes[A.fr].virtualized
+
+def test_A_intersect_input_and_output():
+ spec = PerfectSpecializer(A.ops)
+ spec.find_nodes()
+ spec.intersect_input_and_output()
+ assert spec.nodes[A.fr].escaped
+ assert spec.nodes[A.fr].virtualized
+ assert not spec.nodes[A.n1].escaped
+ assert not spec.nodes[A.n2].escaped
+
+def test_A_optimize_loop():
+ operations = A.ops[:]
+ spec = PerfectSpecializer(operations)
+ spec.find_nodes()
+ spec.intersect_input_and_output()
+ spec.optimize_loop()
+ assert equaloplists(operations, [
+ MergePoint('merge_point', [A.sum, A.n1, A.v], []),
+ ResOperation('int_sub', [A.v, ConstInt(1)], [A.v2]),
+ ResOperation('int_add', [A.sum, A.v], [A.sum2]),
+ Jump('jump', [A.sum2, A.n1, A.v2], []),
+ ])
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py Thu Feb 12 14:38:44 2009
@@ -1,57 +1,14 @@
import py
-from pypy.rpython.lltypesystem.rvirtualizable import VABLERTIPTR
from pypy.rpython.lltypesystem import lltype, lloperation, rclass, llmemory
from pypy.rpython.annlowlevel import llhelper
from pypy.jit.metainterp.policy import StopAtXPolicy
from pypy.rlib.jit import JitDriver
from pypy.jit.metainterp.test.test_basic import LLJitMixin, OOJitMixin
-from pypy.jit.metainterp import heaptracker
from pypy.rpython.lltypesystem.rvirtualizable2 import VABLERTIPTR
-from pypy.rpython.lltypesystem.rvirtualizable2 import VirtualizableAccessor
promote_virtualizable = lloperation.llop.promote_virtualizable
debug_print = lloperation.llop.debug_print
-
-# ____________________________________________________________
-
-XY = lltype.GcStruct(
- 'XY',
- ('parent', rclass.OBJECT),
- ('vable_base', llmemory.Address),
- ('vable_rti', VABLERTIPTR),
- ('x', lltype.Signed),
- ('y', lltype.Signed),
- hints = {'virtualizable2': True},
- adtmeths = {'access': VirtualizableAccessor()})
-XY._adtmeths['access'].initialize(XY, ['x', 'y'])
-
-xy_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
-xy_vtable.name = lltype.malloc(rclass.OBJECT_VTABLE.name.TO, 3, immortal=True)
-xy_vtable.name[0] = 'X'
-xy_vtable.name[1] = 'Y'
-xy_vtable.name[2] = '\x00'
-heaptracker.set_testing_vtable_for_gcstruct(XY, xy_vtable)
-
-XYSUB = lltype.GcStruct(
- 'XYSUB',
- ('parent', XY),
- ('z', lltype.Signed),
- hints = {'virtualizable2': True},
- adtmeths = {'access': VirtualizableAccessor()})
-XYSUB._adtmeths['access'].initialize(XYSUB, ['z'], PARENT=XY)
-
-xysub_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
-xysub_vtable.name = lltype.malloc(rclass.OBJECT_VTABLE.name.TO, 6,
- immortal=True)
-xysub_vtable.name[0] = 'X'
-xysub_vtable.name[1] = 'Y'
-xysub_vtable.name[2] = 'S'
-xysub_vtable.name[3] = 'U'
-xysub_vtable.name[4] = 'B'
-xysub_vtable.name[5] = '\x00'
-heaptracker.set_testing_vtable_for_gcstruct(XYSUB, xysub_vtable)
-
# ____________________________________________________________
class ExplicitVirtualizableTests:
More information about the Pypy-commit
mailing list