[pypy-svn] r63415 - pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph
arigo at codespeak.net
arigo at codespeak.net
Sat Mar 28 19:16:57 CET 2009
Author: arigo
Date: Sat Mar 28 19:16:57 2009
New Revision: 63415
Modified:
pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/runner.py
Log:
[untested] the extended backend interface.
Modified: pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5-loop/pypy/jit/backend/llgraph/llimpl.py Sat Mar 28 19:16:57 2009
@@ -243,6 +243,14 @@
del _variables[:]
return _to_opaque(CompiledLoop())
+def compile_restart(fail_position):
+ fail_op = _from_opaque(fail_position)
+ del _variables[:]
+ c = CompiledLoop()
+ assert fail_op.is_guard()
+ fail_op.subloop = c
+ return _to_opaque(c)
+
def compile_start_int_var(loop):
loop = _from_opaque(loop)
assert not loop.operations
@@ -320,16 +328,13 @@
op.jump_target = loop_target
assert op.opnum == rop.JUMP
assert len(op.args) == len(loop_target.inputargs)
- if loop_target == loop:
- log.info("compiling new loop")
- else:
- log.info("compiling new bridge")
def compile_add_fail(loop, fail_index):
loop = _from_opaque(loop)
op = loop.operations[-1]
assert op.opnum == rop.FAIL
op.fail_index = fail_index
+ return _to_opaque(op)
def compile_suboperations(loop):
loop = _from_opaque(loop)
@@ -926,18 +931,22 @@
COMPILEDLOOP = lltype.Ptr(lltype.OpaqueType("CompiledLoop"))
+OPERATION = lltype.Ptr(lltype.OpaqueType("Operation"))
FRAME = lltype.Ptr(lltype.OpaqueType("Frame"))
MEMOCAST = lltype.Ptr(lltype.OpaqueType("MemoCast"))
_TO_OPAQUE[CompiledLoop] = COMPILEDLOOP.TO
+_TO_OPAQUE[Operation] = OPERATION.TO
_TO_OPAQUE[Frame] = FRAME.TO
_TO_OPAQUE[MemoCast] = MEMOCAST.TO
s_CompiledLoop = annmodel.SomePtr(COMPILEDLOOP)
+s_Operation = annmodel.SomePtr(OPERATION)
s_Frame = annmodel.SomePtr(FRAME)
s_MemoCast = annmodel.SomePtr(MEMOCAST)
setannotation(compile_start, s_CompiledLoop)
+setannotation(compile_restart, s_CompiledLoop)
setannotation(compile_start_int_var, annmodel.SomeInteger())
setannotation(compile_start_ptr_var, annmodel.SomeInteger())
setannotation(compile_add, annmodel.s_None)
@@ -948,7 +957,7 @@
setannotation(compile_add_int_result, annmodel.SomeInteger())
setannotation(compile_add_ptr_result, annmodel.SomeInteger())
setannotation(compile_add_jump_target, annmodel.s_None)
-setannotation(compile_add_fail, annmodel.s_None)
+setannotation(compile_add_fail, s_Operation)
setannotation(compile_suboperations, s_CompiledLoop)
setannotation(new_frame, s_Frame)
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 Sat Mar 28 19:16:57 2009
@@ -75,14 +75,29 @@
self.mixlevelann = annmixlevel
self.fielddescrof_vtable = self.fielddescrof(rclass.OBJECT, 'typeptr')
- def compile_operations(self, loop):
+ def compile_loop(self, loop):
"""In a real assembler backend, this should assemble the given
list of operations. Here we just generate a similar CompiledLoop
instance. The code here is RPython, whereas the code in llimpl
- is not.
+ is not. Returns the compiled loop instance (a black box passed
+ 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
+
+ def compile_bridge(self, fail_op, bridge):
+ """Like compile_loop, but produce the bridge operations going from
+ the guard that precedes the given FAIL operation. It should patch
+ the conditional jump on this guard to now execute the given bridge.
+ """
+ c = llimpl.compile_restart(fail_op._fail_position)
+ var2index = self._get_loop_args(c, bridge)
+ self._compile_branch(c, bridge.operations, var2index, rop.JUMP)
+ return c
+
+ def _get_loop_args(self, c, loop):
var2index = {}
for box in loop.inputargs:
if isinstance(box, history.BoxInt):
@@ -91,9 +106,9 @@
var2index[box] = llimpl.compile_start_ptr_var(c)
else:
raise Exception("box is: %r" % (box,))
- self._compile_branch(c, loop.operations, var2index)
+ return var2index
- def _compile_branch(self, c, operations, var2index):
+ 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:
@@ -112,7 +127,8 @@
x))
if op.is_guard():
c2 = llimpl.compile_suboperations(c)
- self._compile_branch(c2, op.suboperations, var2index.copy())
+ self._compile_branch(c2, op.suboperations, var2index.copy(),
+ rop.FAIL)
x = op.result
if x is not None:
if isinstance(x, history.BoxInt):
@@ -124,10 +140,11 @@
x))
op = operations[-1]
assert op.is_final()
+ assert op.opnum == expected_end
if op.opnum == rop.JUMP:
llimpl.compile_add_jump_target(c, op.jump_target._compiled_version)
elif op.opnum == rop.FAIL:
- llimpl.compile_add_fail(c, len(self.fail_ops))
+ op._fail_position = llimpl.compile_add_fail(c, len(self.fail_ops))
self.fail_ops.append(op)
def execute_operations(self, loop, valueboxes):
More information about the Pypy-commit
mailing list