[pypy-svn] r61833 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Feb 13 16:08:29 CET 2009
Author: fijal
Date: Fri Feb 13 16:08:27 2009
New Revision: 61833
Modified:
pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py
Log:
Pass loop instead of operations into optimize.py
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py Fri Feb 13 16:08:27 2009
@@ -5,7 +5,7 @@
from pypy.rlib import objectmodel
from pypy.rlib.objectmodel import we_are_translated
from pypy.jit.metainterp.history import Const, getkind, getkind_num
-from pypy.jit.metainterp import heaptracker, support, history, optimize
+from pypy.jit.metainterp import heaptracker, support, history
import py
from pypy.tool.ansi_print import ansi_log
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/compile.py Fri Feb 13 16:08:27 2009
@@ -117,7 +117,7 @@
history = metainterp.history
loop.operations = history.operations
close_loop(loop, loop.operations[0], endliveboxes)
- old_loop = optimize.optimize_loop(metainterp, old_loops, loop.operations)
+ old_loop = optimize.optimize_loop(metainterp, old_loops, loop)
if old_loop is not None:
return old_loop
finish_loop_or_bridge(metainterp, loop, loop.operations[0])
@@ -153,7 +153,7 @@
op = Jump('jump', endliveboxes, [])
operations.append(op)
#
- old_loop = optimize.optimize_bridge(metainterp, old_loops, operations)
+ old_loop = optimize.optimize_bridge(metainterp, old_loops, bridge)
if old_loop is None:
return None
bridge.jump_to = old_loop
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 Fri Feb 13 16:08:27 2009
@@ -145,7 +145,7 @@
return "<InstanceNode %s (%s)>" % (self.source, flags)
-def optimize_loop(metainterp, old_loops, operations):
+def optimize_loop(metainterp, old_loops, loop):
if not metainterp._specialize: # for tests only
if old_loops:
return old_loops[0]
@@ -153,11 +153,11 @@
return None
# This does "Perfect specialization" as per doc/jitpl5.txt.
- perfect_specializer = PerfectSpecializer(operations)
+ perfect_specializer = PerfectSpecializer(loop)
perfect_specializer.find_nodes()
perfect_specializer.intersect_input_and_output()
for old_loop in old_loops:
- if perfect_specializer.match_exactly(old_loop.operations):
+ if perfect_specializer.match_exactly(old_loop):
return old_loop
perfect_specializer.optimize_loop()
return None
@@ -177,8 +177,8 @@
class PerfectSpecializer(object):
- def __init__(self, operations):
- self.operations = operations
+ def __init__(self, loop):
+ self.loop = loop
self.nodes = {}
self.dependency_graph = []
@@ -192,10 +192,10 @@
def find_nodes(self):
# Steps (1) and (2)
- for box in self.operations[0].args:
+ for box in self.loop.operations[0].args:
self.nodes[box] = InstanceNode(box, escaped=False, startbox=True)
- for op in self.operations[1:-1]:
+ for op in self.loop.operations[1:-1]:
opname = op.opname
if opname == 'new_with_vtable':
box = op.results[0]
@@ -252,13 +252,13 @@
self.nodes[box] = InstanceNode(box, escaped=True)
def recursively_find_escaping_values(self):
- assert self.operations[0].opname == 'merge_point'
- end_args = self.operations[-1].args
+ assert self.loop.operations[0].opname == 'merge_point'
+ end_args = self.loop.operations[-1].args
memo = {}
for i in range(len(end_args)):
self.nodes[end_args[i]].escape_if_startbox(memo)
for i in range(len(end_args)):
- box = self.operations[0].args[i]
+ box = self.loop.operations[0].args[i]
other_box = end_args[i]
self.nodes[box].add_to_dependency_graph(self.nodes[other_box],
self.dependency_graph)
@@ -275,12 +275,14 @@
def intersect_input_and_output(self):
# Step (3)
self.recursively_find_escaping_values()
- assert self.operations[0].opname == 'merge_point'
- assert self.operations[-1].opname == 'jump'
+ mp = self.loop.operations[0]
+ jump = self.loop.operations[-1]
+ assert mp.opname == 'merge_point'
+ assert jump.opname == 'jump'
specnodes = []
- for i in range(len(self.operations[0].args)):
- enternode = self.nodes[self.operations[0].args[i]]
- leavenode = self.getnode(self.operations[-1].args[i])
+ for i in range(len(mp.args)):
+ enternode = self.nodes[mp.args[i]]
+ leavenode = self.getnode(jump.args[i])
specnodes.append(enternode.intersect(leavenode))
self.specnodes = specnodes
@@ -326,18 +328,19 @@
def optimize_loop(self):
newoperations = []
- if self.operations[0].opname == 'merge_point':
- assert len(self.operations[0].args) == len(self.specnodes)
+ mp = self.loop.operations[0]
+ if mp.opname == 'merge_point':
+ assert len(mp.args) == len(self.specnodes)
for i in range(len(self.specnodes)):
- box = self.operations[0].args[i]
+ box = mp.args[i]
self.specnodes[i].mutate_nodes(self.nodes[box])
else:
- assert self.operations[0].opname == 'catch'
- for box in self.operations[0].args:
+ assert mp.opname == 'catch'
+ for box in mp.args:
self.nodes[box].cls = None
assert not self.nodes[box].virtual
- for op in self.operations:
+ for op in self.loop.operations:
opname = op.opname
if opname == 'merge_point':
args = self.expanded_version_of(op.args)
@@ -429,9 +432,10 @@
newoperations.append(op)
newoperations[0].specnodes = self.specnodes
- self.operations[:] = newoperations
+ self.loop.operations = newoperations
- def match_exactly(self, old_operations):
+ def match_exactly(self, old_loop):
+ old_operations = old_loop.operations
old_mp = old_operations[0]
assert len(old_mp.specnodes) == len(self.specnodes)
for i in range(len(self.specnodes)):
@@ -443,7 +447,7 @@
def match(self, old_operations):
old_mp = old_operations[0]
- jump_op = self.operations[-1]
+ jump_op = self.loop.operations[-1]
assert jump_op.opname == 'jump'
assert len(old_mp.specnodes) == len(jump_op.args)
for i in range(len(old_mp.specnodes)):
@@ -455,7 +459,7 @@
def adapt_for_match(self, old_operations):
old_mp = old_operations[0]
- jump_op = self.operations[-1]
+ jump_op = self.loop.operations[-1]
self.specnodes = old_mp.specnodes
for i in range(len(old_mp.specnodes)):
old_specnode = old_mp.specnodes[i]
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py Fri Feb 13 16:08:27 2009
@@ -32,6 +32,10 @@
# ____________________________________________________________
+class Loop(object):
+ def __init__(self, operations):
+ self.operations = operations
+
class Any(object):
def __eq__(self, other):
return True
@@ -95,7 +99,7 @@
]
def test_A_find_nodes():
- spec = PerfectSpecializer(A.ops)
+ spec = PerfectSpecializer(Loop(A.ops))
spec.find_nodes()
assert spec.nodes[A.sum] is not spec.nodes[A.sum2]
assert spec.nodes[A.n1] is not spec.nodes[A.n2]
@@ -105,7 +109,7 @@
assert not spec.nodes[A.n2].escaped
def test_A_intersect_input_and_output():
- spec = PerfectSpecializer(A.ops)
+ spec = PerfectSpecializer(Loop(A.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert len(spec.specnodes) == 2
@@ -117,16 +121,15 @@
assert isinstance(spec_n.fields[0][1], NotSpecNode)
def test_A_optimize_loop():
- operations = A.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(A.ops))
spec.find_nodes()
spec.intersect_input_and_output()
spec.optimize_loop()
- assert equaloplists(operations, [
- MergePoint('merge_point', [A.sum, 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.v2], []),
+ equaloplists(spec.loop.operations, [
+ MergePoint('merge_point', [A.sum, 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.v2], []),
])
# ____________________________________________________________
@@ -147,7 +150,7 @@
]
def test_B_find_nodes():
- spec = PerfectSpecializer(B.ops)
+ spec = PerfectSpecializer(Loop(B.ops))
spec.find_nodes()
assert spec.nodes[B.n1].cls.source.value == node_vtable_adr
assert not spec.nodes[B.n1].escaped
@@ -155,7 +158,7 @@
assert spec.nodes[B.n2].escaped
def test_B_intersect_input_and_output():
- spec = PerfectSpecializer(B.ops)
+ spec = PerfectSpecializer(Loop(B.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert len(spec.specnodes) == 2
@@ -165,12 +168,11 @@
assert spec_n.known_class.value == node_vtable_adr
def test_B_optimize_loop():
- operations = B.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(B.ops))
spec.find_nodes()
spec.intersect_input_and_output()
spec.optimize_loop()
- assert equaloplists(operations, [
+ equaloplists(spec.loop.operations, [
MergePoint('merge_point', [B.sum, B.n1], []),
# guard_class is gone
ResOperation('getfield_gc', [B.n1, ConstInt(B.ofs_value)], [B.v]),
@@ -202,14 +204,14 @@
]
def test_C_find_nodes():
- spec = PerfectSpecializer(C.ops)
+ spec = PerfectSpecializer(Loop(C.ops))
spec.find_nodes()
assert spec.nodes[C.n1].cls.source.value == node_vtable_adr
assert spec.nodes[C.n1].escaped
assert spec.nodes[C.n2].cls.source.value == node_vtable_adr
def test_C_intersect_input_and_output():
- spec = PerfectSpecializer(C.ops)
+ spec = PerfectSpecializer(Loop(C.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert spec.nodes[C.n2].escaped
@@ -220,12 +222,11 @@
assert spec_n.known_class.value == node_vtable_adr
def test_C_optimize_loop():
- operations = C.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(C.ops))
spec.find_nodes()
spec.intersect_input_and_output()
spec.optimize_loop()
- assert equaloplists(operations, [
+ equaloplists(spec.loop.operations, [
MergePoint('merge_point', [C.sum, C.n1], []),
# guard_class is gone
ResOperation('getfield_gc', [C.n1, ConstInt(C.ofs_value)], [C.v]),
@@ -257,7 +258,7 @@
]
def test_D_intersect_input_and_output():
- spec = PerfectSpecializer(D.ops)
+ spec = PerfectSpecializer(Loop(D.ops))
spec.find_nodes()
py.test.raises(CancelInefficientLoop, spec.intersect_input_and_output)
@@ -280,12 +281,11 @@
ops[-2].liveboxes = [sum2, n2]
def test_E_optimize_loop():
- operations = E.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(E.ops))
spec.find_nodes()
spec.intersect_input_and_output()
spec.optimize_loop()
- assert equaloplists(operations, [
+ equaloplists(spec.loop.operations, [
MergePoint('merge_point', [E.sum, E.v], []),
# guard_class is gone
ResOperation('int_sub', [E.v, ConstInt(1)], [E.v2]),
@@ -293,7 +293,7 @@
ResOperation('guard_true', [E.v2], []),
Jump('jump', [E.sum2, E.v2], []),
])
- guard_op = operations[-2]
+ guard_op = spec.loop.operations[-2]
assert guard_op.opname == 'guard_true'
assert guard_op.liveboxes == [E.sum2, E.v2]
vt = cpu.cast_adr_to_int(node_vtable_adr)
@@ -312,12 +312,11 @@
else:
return []
- operations = E.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(E.ops))
spec.find_nodes()
spec.intersect_input_and_output()
spec.optimize_loop()
- guard_op = operations[-2]
+ guard_op = spec.loop.operations[-2]
fake_history = FakeHistory()
v_sum_b = BoxInt(13)
v_v_b = BoxInt(14)
@@ -363,19 +362,18 @@
ops[-6].liveboxes = liveboxes[:]
def test_F_find_nodes():
- spec = PerfectSpecializer(F.ops)
+ spec = PerfectSpecializer(Loop(F.ops))
spec.find_nodes()
assert not spec.nodes[F.n1].escaped
assert not spec.nodes[F.n2].escaped
def test_F_optimize_loop():
- operations = F.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(F.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert spec.nodes[F.n3].escaped
spec.optimize_loop()
- assert equaloplists(operations, [
+ equaloplists(spec.loop.operations, [
MergePoint('merge_point', [F.sum, F.v, F.n3], []),
ResOperation('int_sub', [F.v, ConstInt(1)], [F.v2]),
ResOperation('int_add', [F.sum, F.v], [F.sum2]),
@@ -409,12 +407,11 @@
ops[-2].liveboxes = [sum2, n2]
def test_G_optimize_loop():
- operations = G.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(G.ops))
spec.find_nodes()
spec.intersect_input_and_output()
spec.optimize_loop()
- assert equaloplists(operations, [
+ equaloplists(spec.loop.operations, [
MergePoint('merge_point', [G.sum, G.v], []),
# guard_class is gone
ResOperation('int_sub', [G.v, ConstInt(1)], [G.v2]),
@@ -422,7 +419,7 @@
ResOperation('guard_true', [G.v2], []),
Jump('jump', [G.sum2, ConstInt(124)], []),
])
- guard_op = operations[-2]
+ guard_op = spec.loop.operations[-2]
assert guard_op.opname == 'guard_true'
assert guard_op.liveboxes == [G.sum2, ConstInt(124)]
vt = cpu.cast_adr_to_int(node_vtable_adr)
@@ -457,7 +454,7 @@
]
def test_H_intersect_input_and_output():
- spec = PerfectSpecializer(H.ops)
+ spec = PerfectSpecializer(Loop(H.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert spec.nodes[H.n0].escaped
@@ -485,7 +482,7 @@
]
def test_I_intersect_input_and_output():
- spec = PerfectSpecializer(I.ops)
+ spec = PerfectSpecializer(Loop(I.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert spec.nodes[I.n0].escaped
@@ -515,10 +512,40 @@
]
def test_J_intersect_input_and_output():
- spec = PerfectSpecializer(J.ops)
+ spec = PerfectSpecializer(Loop(J.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert not spec.nodes[J.n0].escaped
assert spec.nodes[J.n1].escaped
assert not spec.nodes[J.n2].escaped
+# ____________________________________________________________
+
+class K:
+ locals().update(A.__dict__) # :-)
+ sum3 = BoxInt(3)
+ v3 = BoxInt(4)
+ ops = [
+ MergePoint('merge_point', [sum, n1], []),
+ ResOperation('guard_class', [n1, ConstAddr(node_vtable, cpu)], []),
+ ResOperation('getfield_gc', [n1, ConstInt(ofs_value)], [v]),
+ ResOperation('int_sub', [v, ConstInt(1)], [v2]),
+ ResOperation('int_add', [sum, v], [sum2]),
+ ResOperation('getfield_gc', [n1, ConstInt(ofs_value)], [v3]),
+ ResOperation('int_add', [sum2, v3], [sum3]),
+ Jump('jump', [sum2, n1], []),
+ ]
+
+def test_K_optimize_loop():
+ py.test.skip("incomplete test")
+ spec = PerfectSpecializer(Loop(K.ops))
+ spec.find_nodes()
+ spec.intersect_input_and_output()
+ spec.optimize_loop()
+ assert equaloplists(operations, [
+ MergePoint('merge_point', [K.sum, K.v], []),
+ ResOperation('int_sub', [K.v, ConstInt(1)], [K.v2]),
+ ResOperation('int_add', [K.sum, K.v], [K.sum2]),
+ Jump('jump', [K.sum2, K.v2], []),
+ ])
+
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py Fri Feb 13 16:08:27 2009
@@ -11,7 +11,7 @@
NotSpecNode)
from pypy.jit.metainterp.virtualizable import VirtualizableDesc
from pypy.jit.metainterp.test.test_optimize import (cpu, NODE, node_vtable,
- equaloplists)
+ equaloplists, Loop)
# ____________________________________________________________
@@ -93,12 +93,12 @@
ops[1].vdesc = xy_desc
def test_A_find_nodes():
- spec = PerfectSpecializer(A.ops)
+ spec = PerfectSpecializer(Loop(A.ops))
spec.find_nodes()
assert spec.nodes[A.fr].virtualized
def test_A_intersect_input_and_output():
- spec = PerfectSpecializer(A.ops)
+ spec = PerfectSpecializer(Loop(A.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert spec.nodes[A.fr].escaped
@@ -108,17 +108,16 @@
assert isinstance(spec.specnodes[1], VirtualizableSpecNode)
def test_A_optimize_loop():
- operations = A.ops[:]
- spec = PerfectSpecializer(operations)
+ spec = PerfectSpecializer(Loop(A.ops))
spec.find_nodes()
spec.intersect_input_and_output()
spec.optimize_loop()
- assert equaloplists(operations, [
- MergePoint('merge_point', [A.sum, A.fr, 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.fr, A.v2], []),
- ])
+ equaloplists(spec.loop.operations, [
+ MergePoint('merge_point', [A.sum, A.fr, 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.fr, A.v2], []),
+ ])
# ____________________________________________________________
@@ -145,7 +144,7 @@
ops[1].vdesc = xy_desc
def test_B_intersect_input_and_output():
- spec = PerfectSpecializer(B.ops)
+ spec = PerfectSpecializer(Loop(B.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert spec.nodes[B.fr].escaped
@@ -180,7 +179,7 @@
ops[1].vdesc = xy_desc
def test_C_intersect_input_and_output():
- spec = PerfectSpecializer(C.ops)
+ spec = PerfectSpecializer(Loop(C.ops))
spec.find_nodes()
spec.intersect_input_and_output()
assert spec.nodes[C.fr].escaped
More information about the Pypy-commit
mailing list