Author: Hakan Ardo <ha...@debian.org> Branch: jit-targets Changeset: r48711:1860421891fe Date: 2011-11-03 19:18 +0100 http://bitbucket.org/pypy/pypy/changeset/1860421891fe/
Log: use TargetToken to refere to a target diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py --- a/pypy/jit/backend/llgraph/llimpl.py +++ b/pypy/jit/backend/llgraph/llimpl.py @@ -8,6 +8,7 @@ from pypy.objspace.flow.model import Variable, Constant from pypy.annotation import model as annmodel from pypy.jit.metainterp.history import REF, INT, FLOAT +from pypy.jit.metainterp import history from pypy.jit.codewriter import heaptracker from pypy.rpython.lltypesystem import lltype, llmemory, rclass, rstr, rffi from pypy.rpython.ootypesystem import ootype @@ -339,16 +340,20 @@ assert isinstance(type, str) and len(type) == 1 op.args.append(Descr(ofs, type, arg_types=arg_types)) -def compile_add_loop_token(loop, descr, clt): +def compile_add_loop_token(loop, descr): if we_are_translated(): raise ValueError("CALL_ASSEMBLER not supported") loop = _from_opaque(loop) op = loop.operations[-1] op.descr = weakref.ref(descr) - if op.opnum == rop.TARGET: - descr.compiled_loop_token = clt - descr.target_opindex = len(loop.operations) - descr.target_arguments = op.args + +def compile_add_target_token(loop, descr): + compiled_version = loop + loop = _from_opaque(loop) + op = loop.operations[-1] + descr.compiled_version = compiled_version + descr.target_opindex = len(loop.operations) + descr.target_arguments = op.args def compile_add_var(loop, intvar): loop = _from_opaque(loop) @@ -384,11 +389,19 @@ _variables.append(v) return r -def compile_add_jump_target(loop, loop_target, target_opindex, target_inputargs): +def compile_add_jump_target(loop, targettoken): loop = _from_opaque(loop) - loop_target = _from_opaque(loop_target) - if not target_inputargs: + if isinstance(targettoken, history.LoopToken): + loop_target = _from_opaque(targettoken.compiled_loop_token.compiled_version) + target_opindex = 0 target_inputargs = loop_target.inputargs + elif isinstance(targettoken, history.TargetToken): + loop_target = _from_opaque(targettoken.compiled_version) + target_opindex = targettoken.target_opindex + target_inputargs = targettoken.target_arguments + else: + assert False + op = loop.operations[-1] op.jump_target = loop_target op.jump_target_opindex = target_opindex diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -136,7 +136,7 @@ clt = original_loop_token.compiled_loop_token clt.loop_and_bridges.append(c) clt.compiling_a_bridge() - self._compile_loop_or_bridge(c, inputargs, operations, clt) + self._compile_loop_or_bridge(c, inputargs, operations) old, oldindex = faildescr._compiled_fail llimpl.compile_redirect_fail(old, oldindex, c) @@ -151,16 +151,14 @@ clt.loop_and_bridges = [c] clt.compiled_version = c looptoken.compiled_loop_token = clt - looptoken.target_opindex = 0 - looptoken.target_arguments = None - self._compile_loop_or_bridge(c, inputargs, operations, clt) + self._compile_loop_or_bridge(c, inputargs, operations) def free_loop_and_bridges(self, compiled_loop_token): for c in compiled_loop_token.loop_and_bridges: llimpl.mark_as_free(c) model.AbstractCPU.free_loop_and_bridges(self, compiled_loop_token) - def _compile_loop_or_bridge(self, c, inputargs, operations, clt): + def _compile_loop_or_bridge(self, c, inputargs, operations): var2index = {} for box in inputargs: if isinstance(box, history.BoxInt): @@ -172,10 +170,10 @@ var2index[box] = llimpl.compile_start_float_var(c) else: raise Exception("box is: %r" % (box,)) - self._compile_operations(c, operations, var2index, clt) + self._compile_operations(c, operations, var2index) return c - def _compile_operations(self, c, operations, var2index, clt): + def _compile_operations(self, c, operations, var2index): for op in operations: llimpl.compile_add(c, op.getopnum()) descr = op.getdescr() @@ -184,7 +182,9 @@ descr.arg_types) if isinstance(descr, history.LoopToken): if op.getopnum() != rop.JUMP: - llimpl.compile_add_loop_token(c, descr, clt) + llimpl.compile_add_loop_token(c, descr) + if isinstance(descr, history.TargetToken) and op.getopnum() == rop.TARGET: + llimpl.compile_add_target_token(c, descr) if self.is_oo and isinstance(descr, (OODescr, MethDescr)): # hack hack, not rpython c._obj.externalobj.operations[-1].setdescr(descr) @@ -238,10 +238,7 @@ assert op.is_final() if op.getopnum() == rop.JUMP: targettoken = op.getdescr() - assert isinstance(targettoken, history.LoopToken) - compiled_version = targettoken.compiled_loop_token.compiled_version - opindex = targettoken.target_opindex - llimpl.compile_add_jump_target(c, compiled_version, opindex, targettoken.target_arguments) + llimpl.compile_add_jump_target(c, targettoken) elif op.getopnum() == rop.FINISH: faildescr = op.getdescr() index = self.get_fail_descr_number(faildescr) diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py --- a/pypy/jit/backend/test/runner_test.py +++ b/pypy/jit/backend/test/runner_test.py @@ -3,7 +3,7 @@ AbstractDescr, BasicFailDescr, BoxInt, Box, BoxPtr, - LoopToken, + LoopToken, TargetToken, ConstInt, ConstPtr, BoxObj, ConstObj, BoxFloat, ConstFloat) @@ -2971,7 +2971,7 @@ i2 = BoxInt() i3 = BoxInt() looptoken = LoopToken() - targettoken = LoopToken() + targettoken = TargetToken() faildescr = BasicFailDescr(2) operations = [ ResOperation(rop.INT_ADD, [i0, ConstInt(1)], i1), diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py --- a/pypy/jit/metainterp/history.py +++ b/pypy/jit/metainterp/history.py @@ -765,6 +765,9 @@ def dump(self): self.compiled_loop_token.cpu.dump_loop_token(self) +class TargetToken(AbstractDescr): + pass + class TreeLoop(object): inputargs = None operations = None _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit