[pypy-svn] r63444 - in pypy/branch/pyjitpl5-loop/pypy/jit: backend/llgraph metainterp
arigo at codespeak.net
arigo at codespeak.net
Tue Mar 31 13:02:53 CEST 2009
Author: arigo
Date: Tue Mar 31 13:02:50 2009
New Revision: 63444
Modified:
pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/runner.py
pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/compile.py
pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/history.py
pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/optimize.py
pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/resoperation.py
Log:
More in-progress stuff...
Modified: pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/runner.py Tue Mar 31 13:02:50 2009
@@ -83,6 +83,7 @@
back to execute_operations()).
"""
c = llimpl.compile_start()
+ loop._compiled_version = c
var2index = self._get_loop_args(c, loop)
self._compile_branch(c, loop.operations, var2index, rop.JUMP)
return c
@@ -111,7 +112,7 @@
def _compile_branch(self, c, operations, var2index, expected_end):
for op in operations:
llimpl.compile_add(c, op.opnum)
- if op.descr is not None:
+ if isinstance(op.descr, Descr):
llimpl.compile_add_descr(c, op.descr.ofs, op.descr.type)
for x in op.args:
if isinstance(x, history.Box):
Modified: pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/compile.py (original)
+++ pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/compile.py Tue Mar 31 13:02:50 2009
@@ -103,29 +103,19 @@
def compile_fresh_loop(metainterp, old_loops):
history = metainterp.history
- old_loop = optimize.optimize_loop(metainterp.options, old_loops,
- history, metainterp.cpu)
- if old_loop is not None:
- return old_loop
loop = create_empty_loop(metainterp)
loop.inputargs = history.inputargs
- loop.specnodes = history.specnodes
loop.operations = history.operations
loop.operations[-1].jump_target = loop
- mark_keys_in_loop(loop, loop.operations)
+ old_loop = optimize.optimize_loop(metainterp.options, old_loops,
+ loop, metainterp.cpu)
+ if old_loop is not None:
+ return old_loop
send_loop_to_backend(metainterp, loop)
metainterp.stats.loops.append(loop)
old_loops.append(loop)
return loop
-def mark_keys_in_loop(loop, operations):
- for op in operations:
- if op.is_guard():
- mark_keys_in_loop(loop, op.suboperations)
- op = operations[-1]
- if op.opnum == rop.FAIL:
- op.key.loop = loop
-
def send_loop_to_backend(metainterp, loop):
metainterp.cpu.compile_loop(loop)
metainterp.stats.compiled_count += 1
@@ -138,6 +128,8 @@
#temp = TreeLoop('temp')
#temp.operations = metainterp.history.operations
#metainterp.stats.view(extraloops=[temp])
+ history = metainterp.history
+ xxx
target_loop = optimize.optimize_bridge(metainterp.options, old_loops,
metainterp.history, metainterp.cpu)
if target_loop is None:
Modified: pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/history.py Tue Mar 31 13:02:50 2009
@@ -403,11 +403,19 @@
if op.is_guard():
_list_all_operations(result, op.suboperations, omit_fails)
+
+class ResumeDescr(AbstractDescr):
+ def __init__(self, guard_op, resume_info, history, history_guard_index):
+ self.resume_info = resume_info
+ self.guard_op = guard_op
+ self.counter = 0
+ self.history = history
+ self.history_guard_index = history_guard_index
+
# ____________________________________________________________
class RunningMatcher(object):
- specnodes = None
def __init__(self, cpu):
self.cpu = cpu
self.inputargs = None
Modified: pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/optimize.py (original)
+++ pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/optimize.py Tue Mar 31 13:02:50 2009
@@ -192,7 +192,10 @@
if self.virtualized: flags += 'V'
return "<InstanceNode %s (%s)>" % (self.source, flags)
-def optimize_loop(options, old_loops, history, cpu=None):
+# ____________________________________________________________
+
+
+def optimize_loop(options, old_loops, loop, cpu=None):
if not options.specialize: # for tests only
if old_loops:
return old_loops[0]
@@ -200,7 +203,7 @@
return None
# This does "Perfect specialization" as per doc/jitpl5.txt.
- perfect_specializer = PerfectSpecializer(history, options, cpu)
+ perfect_specializer = PerfectSpecializer(loop, options, cpu)
perfect_specializer.find_nodes()
perfect_specializer.intersect_input_and_output()
for old_loop in old_loops:
@@ -209,12 +212,26 @@
perfect_specializer.optimize_loop()
return None
+def optimize_bridge(options, loop, history, cpu=None):
+ if not options.specialize: # for tests only
+ return old_loops[0]
+
+ perfect_specializer = PerfectSpecializer(history, options, cpu)
+ perfect_specializer.find_nodes()
+ for old_loop in old_loops:
+ if perfect_specializer.match(old_loop):
+ perfect_specializer.optimize_loop()
+ return old_loop
+ return None # no loop matches
+
+# ____________________________________________________________
+
class PerfectSpecializer(object):
_allow_automatic_node_creation = False
- def __init__(self, history, options=Options(), cpu=None):
- self.history = history
+ def __init__(self, loop, options=Options(), cpu=None):
+ self.loop = loop
self.options = options
self.cpu = cpu
self.nodes = {}
@@ -274,14 +291,14 @@
def find_nodes(self):
# Steps (1) and (2)
self.first_escaping_op = True
- if self.history.inputargs is not None:
- for box in self.history.inputargs:
+ if self.loop.inputargs is not None:
+ for box in self.loop.inputargs:
self.nodes[box] = InstanceNode(box, escaped=False,
startbox=True)
else:
self._allow_automatic_node_creation = True
#
- for op in self.history.operations:
+ for op in self.loop.operations:
#print '| ' + op.repr()
opnum = op.opnum
if opnum == rop.JUMP:
@@ -389,15 +406,15 @@
self.nodes[box] = InstanceNode(box, escaped=True)
def recursively_find_escaping_values(self):
- end_args = self.history.operations[-1].args
- assert len(self.history.inputargs) == len(end_args)
+ end_args = self.loop.operations[-1].args
+ assert len(self.loop.inputargs) == len(end_args)
memo = {}
for i in range(len(end_args)):
end_box = end_args[i]
if isinstance(end_box, Box):
self.nodes[end_box].escape_if_startbox(memo, self.cpu)
for i in range(len(end_args)):
- box = self.history.inputargs[i]
+ box = self.loop.inputargs[i]
other_box = end_args[i]
if isinstance(other_box, Box):
self.nodes[box].add_to_dependency_graph(self.nodes[other_box],
@@ -415,11 +432,11 @@
def intersect_input_and_output(self):
# Step (3)
self.recursively_find_escaping_values()
- jump = self.history.operations[-1]
+ jump = self.loop.operations[-1]
assert jump.opnum == rop.JUMP
specnodes = []
- for i in range(len(self.history.inputargs)):
- enternode = self.nodes[self.history.inputargs[i]]
+ for i in range(len(self.loop.inputargs)):
+ enternode = self.nodes[self.loop.inputargs[i]]
leavenode = self.getnode(jump.args[i])
specnodes.append(enternode.intersect(leavenode, self.nodes))
self.specnodes = specnodes
@@ -588,13 +605,13 @@
self._allow_automatic_node_creation = False
newoperations = []
exception_might_have_happened = False
- if self.history.inputargs is not None:
+ if self.loop.inputargs is not None:
# closing a loop
- assert len(self.history.inputargs) == len(self.specnodes)
+ assert len(self.loop.inputargs) == len(self.specnodes)
for i in range(len(self.specnodes)):
- box = self.history.inputargs[i]
+ box = self.loop.inputargs[i]
self.specnodes[i].mutate_nodes(self.nodes[box])
- newinputargs = self.expanded_version_of(self.history.inputargs,
+ newinputargs = self.expanded_version_of(self.loop.inputargs,
None)
else:
# making a bridge
@@ -604,7 +621,7 @@
assert not node.virtual
newinputargs = None
#
- for op in self.history.operations:
+ for op in self.loop.operations:
opnum = op.opnum
if opnum == rop.JUMP:
args = self.expanded_version_of(op.args, newoperations)
@@ -764,9 +781,9 @@
self.nodes[box] = instnode
newoperations.append(op)
#
- self.history.specnodes = self.specnodes
- self.history.inputargs = newinputargs
- self.history.operations = newoperations
+ self.loop.specnodes = self.specnodes
+ self.loop.inputargs = newinputargs
+ self.loop.operations = newoperations
# def cleanup_field_caches(self, newoperations):
# # we need to invalidate everything
Modified: pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/pyjitpl.py Tue Mar 31 13:02:50 2009
@@ -651,8 +651,9 @@
if box is not None:
extraargs = [box] + extraargs
guard_op = self.metainterp.history.record(opnum, extraargs, None)
- op = history.ResOperation(rop.FAIL, liveboxes, None)
- op.key = ResumeKey(guard_op, resume_info)
+ resumedescr = history.ResumeDescr(guard_op, resume_info,
+ self.metainterp.history, len(self.metainterp.history.operations)-1)
+ op = history.ResOperation(rop.FAIL, liveboxes, None, descr=resumedescr)
guard_op.suboperations = [op]
self.pc = saved_pc
return guard_op
@@ -829,7 +830,8 @@
def handle_guard_failure(self, guard_failure):
self.initialize_state_from_guard_failure(guard_failure)
- key = guard_failure.key
+ key = guard_failure.descr
+ assert isinstance(key, history.ResumeDescr)
try:
if key.guard_op.opnum in (rop.GUARD_NO_EXCEPTION,
rop.GUARD_EXCEPTION):
@@ -929,16 +931,18 @@
def initialize_state_from_guard_failure(self, guard_failure):
# guard failure: rebuild a complete MIFrame stack
- if self.state.must_compile_from_failure(guard_failure.key):
+ resumedescr = guard_failure.descr
+ assert isinstance(resumedescr, history.ResumeDescr)
+ if self.state.must_compile_from_failure(resumedescr):
self.history = history.History(self.cpu)
- suboperations = guard_failure.key.guard_op.suboperations
+ suboperations = resumedescr.guard_op.suboperations
for i in range(len(suboperations)-1):
self.history.operations.append(suboperations[i])
else:
self.history = history.BlackHole(self.cpu)
# the BlackHole is invalid because it doesn't start with
# guard_failure.key.guard_op.suboperations, but that's fine
- self.rebuild_state_after_failure(guard_failure.key.resume_info,
+ self.rebuild_state_after_failure(resumedescr.resume_info,
guard_failure.args)
def handle_exception(self):
@@ -991,10 +995,3 @@
class GenerateMergePoint(Exception):
def __init__(self, args):
self.argboxes = args
-
-class ResumeKey(object):
- def __init__(self, guard_op, resume_info):
- self.resume_info = resume_info
- self.guard_op = guard_op
- self.counter = 0
- # self.loop = ... set in compile.py
Modified: pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/branch/pyjitpl5-loop/pypy/jit/metainterp/resoperation.py Tue Mar 31 13:02:50 2009
@@ -5,9 +5,6 @@
# for 'jump': points to the target loop
jump_target = None
- # for 'fail'
- key = None
-
# for 'guard_*'
suboperations = None
@@ -34,7 +31,6 @@
def clone(self):
res = ResOperation(self.opnum, self.args, self.result, self.descr)
res.jump_target = self.jump_target
- res.key = self.key
res.vdesc = self.vdesc
return res
More information about the Pypy-commit
mailing list